记录:https://www.luogu.com.cn/record/186945247
我的贪心策略:
代码:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string a1;
struct numberr
{
int cur,pos;
bool deleted=0;
}a[260];
bool cmp(numberr x,numberr y)
{
if(x.cur==y.cur) return x.pos<y.pos;
return x.cur>y.cur;
}
bool cmp2(numberr x,numberr y)
{
return x.pos<y.pos;
}
int n,len;
int main()
{
cin>>a1>>n;
len=a1.size();
for(int i=0;i<len;i++)
{
a[i].cur=int(a1[i]-'0');
a[i].pos=i;
}
sort(a,a+len,cmp);
for(int i=0;i<n;i++)
{
a[i].deleted=1;
}
sort(a,a+len,cmp2);
if(n==len)
{
cout<<0<<'\n';
return 0;
}
for(int i=0;i<len;i++)
{
//cout<<i;
if(a[i].deleted) continue;
cout<<a[i].cur;
}
return 0;
}