PAT level B-output PATest

Title description
Given a string of English letters that does not exceed 10 ​4​​ in length .

Please character re-adjust the order, according to PATestPATest....this order output, and ignore other characters.

Of course, the number of six characters is not necessarily the same.

If the character has some kind of finished output, the remaining characters based upon the PATestorder of printing until all characters are output.

Input format
input is given a length of not more than 10 in a row . 4 , the English letters made of only non-empty string.

Output format The
sorted string is output in one line according to the requirements of the title. The title guarantees that the output is not empty.

Enter the sample
redlesPayBestPATTopTeePHPereatitAPPT

Output sample
PATestPATestPTetPTePePee


answer:

#include <iostream>
using namespace std;

int cnt[150];

int main()
{
    
    
	string s;
	cin >> s;
	
	for (int i = 0; i < s.size(); i ++) cnt[s[i]] ++;
	
	while(cnt['P'] || cnt['A'] || cnt['T'] || cnt['e'] || cnt['s'] || cnt['t'])
	{
    
    
		if(cnt['P']) cout << 'P', cnt['P'] --;
		if(cnt['A']) cout << 'A', cnt['A'] --;
		if(cnt['T']) cout << 'T', cnt['T'] --; 
		if(cnt['e']) cout << 'e', cnt['e'] --;
		if(cnt['s']) cout << 's', cnt['s'] --; 
		if(cnt['t']) cout << 't', cnt['t'] --; 
	}
	
	return 0;
} 

Guess you like

Origin blog.csdn.net/weixin_46239370/article/details/113862201