#include <iostream>
#include <cstdio>
#include <string.h>
#include <cstring>
#include <algorithm>
using namespace std;
struct node
{
char letter;
int total;
}c[100];
bool cmp(node x,node y)
{
return x.total<y.total;
}
int main()
{
char a[100002];
gets(a);
char b[100];
int k1=1,k2=1,k3=1;
for(int i='a';i<='z';i++)
{
b[k1++]=i;
c[k2++].letter=i;
c[k3++].total=0;
}
int l=strlen(a);
for(int i=1;i<=26;i++)
{
for(int j=0;j<l;j++)
{
if(a[j]==b[i])
{
c[i].total++;
}
}
}
sort(c+1,c+27,cmp);
int n;
cin>>n;
if(n>=l) cout<<"0"<<endl;
else
{
int sum=0;
int kk=1;
while(sum<=n)
{
sum=sum+c[kk++].total;
}
for(int i=0;i<l;i++)
{
for(int j=1;j<kk-1;j++)
{
if(a[i]==c[j].letter) a[i]='0';
}
}
int ssum=0;
for(int i=1;i<kk-1;i++)
{
ssum=ssum+c[i].total;
c[i].total=0;
}
if(ssum+c[kk-1].total==n)
{
for(int i=0;i<l;i++)
if(a[i]==c[kk-1].letter) a[i]='0';
}
int allsum=0;
for(int i=1;i<=26;i++)
{
if(c[i].total!=0) allsum++;
}
cout<<allsum<<endl;
for(int i=0;i<l;i++)
{
if(a[i]!='0') cout<<a[i];
}
cout<<endl;
}
return 0;
}
Vjudge 4.12 省赛训练赛 A. Homework
最新推荐文章于 2020-07-16 02:20:32 发布