Topic links : https://pintia.cn/problem-sets/994805260223102976/problems/994805280074743808
Title Description
Given a length of not more than 10 ^ 4, the string consisting of letters only. 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
Input is given a length of not more than 10 ^ 4 in a row, only non-empty string composed of English letters.
Output
in a row by topic string output ordering requirements. Topic ensure that the output is not empty.
Sample input
redlesPayBestPATTopTeePHPereatitAPPT
Sample output
PATestPATestPTetPTePePee
Code
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
map<char, int> m;
m['P'] = 0; m['A'] = 0; m['T'] = 0; m['e'] = 0; m['s'] = 0; m['t'] = 0;
char str[7] = {'P', 'A', 'T', 'e', 's', 't'};
bool flag = true;
string s1;
getline(cin, s1);
for(int i = 0; i < s1.size(); i++)
if(s1[i] == 'P' || s1[i] == 'A' || s1[i] == 'T' || s1[i] == 'e' || s1[i] == 's' || s1[i] == 't')
m[s1[i]]++;
while(flag) {
flag = false;
for(int i = 0; i < 6; i++) {
if(m[str[i]] > 0) {
cout << str[i];
m[str[i]]--;
flag = true;
}
}
}
cout<<endl;
return 0;
}