1043 output PATest (20 minutes)
given a length of not more than 10 ^ 4, only the character strings of letters. Please character re-adjust the order, according to PATestPATest ... in that order output, and ignore other characters. Of course, the number of six kinds of characters is not necessarily as much, if some kind of character output has finished, the remaining characters based upon the order of PATest print until all characters are output.
Input format:
Enter a given length of no more than 10 ^ 4 in a row, only non-empty string composed of English letters.
Output format:
in one line the output string by topic ordering requirements. Topic ensure that the output is not empty.
Sample input:
redlesPayBestPATTopTeePHPereatitAPPT
Sample output:
PATestPATestPTetPTePePee
Problem-solving ideas: The number of P, A, T, e, s, t are stored in the map appears, the final output can be sequentially
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
int main(){
string a,result;
map<char, int> cmap;
cin >> a;
for (int i = 0; i < a.length(); i++){
if (a[i] == 'P' || a[i] == 'A' || a[i] == 'T' || a[i] == 'e' || a[i] == 's' || a[i] == 't'){
cmap[a[i]]++;
}
}
while (true){
if (cmap['P'] == 0 && cmap['A'] == 0 && cmap['T'] == 0 && cmap['e'] == 0 && cmap['s'] == 0 && cmap['t'] == 0){
break;
}
if (cmap['P'] != 0){
cmap['P']--;
result += 'P';
}
if (cmap['A'] != 0){
cmap['A']--;
result +='A';
}
if (cmap['T'] != 0){
cmap['T']--;
result += 'T';
}
if (cmap['e'] != 0){
cmap['e']--;
result += 'e';
}
if (cmap['s'] != 0){
cmap['s']--;
result += 's';
}
if (cmap['t'] != 0){
cmap['t']--;
result += 't';
}
}
cout << result << endl;
return 0;
}