-
Notifications
You must be signed in to change notification settings - Fork 0
/
100_C.cpp
86 lines (81 loc) · 1.05 KB
/
100_C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<climits>
using namespace std;
string toString(char c,int count)
{
string ret;
for(int i=0;i<count;i++)
{
ret+=c;
}
return ret;
}
int main()
{
string s;
cin>>s;
int k;
cin>>k;
int n = (int)s.length();
if(k>=n)
{
cout<<"0"<<endl;
string t;
cout<<endl;
return 0;
}
vector<int>a(26);
for(int i=0;i<(int)s.length();i++)
{
a[s[i]-'a']++;
}
bool found = false;
while(!found && k>0)
{
int minm = INT_MAX;
int index = 0;
for(int i=0;i<26;i++)
{
if(a[i]>0 && k>=a[i])
{
if(a[i]<minm)
{
minm = a[i];
index = i;
}
}
}
if(minm==INT_MAX)
{
found = true;
continue;
}
int t = a[index];
a[index] = 0;
k-=t;
string m;
for(int i=0;i<(int)s.length();i++)
{
if(s[i] == (char)(index+'a'))
continue;
m+=s[i];
}
s = m;
}
int count = 0;
for(int i=0;i<(int)s.length();i++)
{
if(a[s[i]-'a']>0)
{
count++;
a[s[i]-'a'] = 0;
}
}
cout<<count<<endl;
cout<<s<<endl;
return 0;
}