codeforces 101A HOME 정렬

4152 단어

Description
Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting ofn small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to learn those letters. That's why he decided to lose some part of the string (not necessarily a connected part). The lost part can consist of any number of segments of any length, at any distance from each other. However, Gerald knows that if he loses more thank characters, it will be very suspicious.
Find the least number of distinct characters that can remain in the string after no more thank characters are deleted. You also have to find any possible way to delete the characters.
Input
The first input data line contains a string whose length is equal to n (1 ≤ n ≤ 105). The string consists of lowercase Latin letters. The second line contains the numberk (0 ≤ k ≤ 105).
Output
Print on the first line the only number m — the least possible number of different characters that could remain in the given string after it loses no more thank characters.
Print on the second line the string that Gerald can get after some characters are lost. The string should have exactlym distinct characters. The final string should be the subsequence of the initial string. If Gerald can get several different strings with exactlym distinct characters, print any of them.
Sample Input
Input
aaaaa
4

Output
1
aaaaa

Input
abacaba
4

Output
1
aaaa

Input
abcdefgh
10

Output
0


Sample Output
Hint
In the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a"from 1 to 5 in length.
In the second sample you are allowed to delete 4 characters. You cannot delete all the characters, because the string has length equal to 7. However, you can delete all characters apart from "a"(as they are no more than four), which will result in the "aaaa"string.
In the third sample you are given a line whose length is equal to 8, and k = 10, so that the whole line can be deleted. The correct answer is 0 and an empty string.
제목: 어려운 제목이다. 영어 찌꺼기에는 천서다. 제목은 한 줄의 문자를 정해서 최대 k개를 삭제하고 남겨진 문자의 종류를 최소화하는 것이다.
사고방식: 각 문자의 개수를 통계한 다음에 정렬(승차순)을 한 다음에 총수 <=k의 모든 문자를 삭제하고 원래의 문자순으로 출력한다.
AC 코드:
#include #include #include #include using namespace std;
struct point {     int sum;     char c; }; point po[27]; char a[100010]; int k; int tol;
int cmpsum(point a,point b){     return a.sum=0;len--){             po[a[len]-'a'].sum++;             po[a[len]-'a'].c= a[len]; }//통계sort(po,po+26,cmpsum);//tol=0 정렬하기;        int i;         for(i=0;i<26;i++){             if(po[i].sum==0){continue;}             tol+=po[i].sum;             if(tol<=k){                 for(int j=0;jk){break;} }//문자printf("%d", 26-i) 삭제;        for( int j=0;j그야말로 폭발적이다. 시합할 때 문제도 못 읽는데 하기는커녕 영어 찌꺼기의 어려움이야,,,,,,,,,,,,,,,

좋은 웹페이지 즐겨찾기