PAT Basic 1043 output PATest (20 minutes)

Given a length of not more than 10 . 4 
, the string composed only of letters. Please character re-adjust the order, so order by PATestPATest .... 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 the length of a given line does not exceed 10 . 4 
, the non-empty string composed only of 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


#include <iostream>
#include <cstdlib>
using namespace std;

int main(){
    string str;
    cin>>str;
    int P=0,A=0,T=0,e=0,s=0,t=0;
    for(int i=0;i<str.length();i++){
        if(str[i]=='P') P++;
        if(str[i]=='A') A++;
        if(str[i]=='T') T++;
        if(str[i]=='e') e++;
        if(str[i]=='s') s++;
        if(str[i]=='t') t++;
    }
    while(true){
        if(P!=0) {
            cout<<"P";P--;
        }
        if(A!=0) {
            cout<<"A";A--;
        }
        if(T!=0) {
            cout<<"T";T--;
        }
        if(e!=0) {
            cout<<"e";e--;
        }
        if(s!=0) {
            cout<<"s";s--;
        }
        if(t!=0) {
            cout<<"t";t--;
        }
        if(P==0&&A==0&&T==0&&e==0&&s==0&&t==0) break;
    }
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11355593.html