codeforces 101A HOME 정렬
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
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
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.