SDUT 算法训练赛 (简单字符串操作)


#include<bits/stdc++.h>
using namespace std;
const int maxn=400005;
char a[maxn],b[maxn],temp;
int main()
{
    int n,k,m=0;
    cin>>n>>k>>a;
    int len=strlen(a);
    int cnt=-1;
    while(k)
    {
        cnt++;
        temp='a'+cnt;
        for(int i=0; i<len; i++)
        {
        if(k==0)
        break;
            if(a[i]==temp)
            {
            a[i]=-1;
            k--;
            }

        }
    }
    for(int i=0; i<len; i++)
    if(a[i]!=-1)
    b[m++]=a[i];
    for(int i=0; i<m; i++)
        cout<<b[i];
    cout<<endl;

    return 0;

}

猜你喜欢

转载自blog.csdn.net/beposit/article/details/80905986
今日推荐