PAT B 1043 outputs PATest (20 minutes)

1043 output PATest (20 minutes)

Given a length of not more than 104, only a character string composed 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 formats:

Input is given a length of not more than 104 in a row, only non-empty string composed of English letters.
Output formats:

Title character string in a row by ordering the required output. Topic ensure that the output is not empty.
Sample input:

redlesPayBestPATTopTeePHPereatitAPPT
sample output:

PATestPATestPTetPTePePee
Author: CHEN, Yue
units: Zhejiang University
Time limit: 400 ms
Memory Limit: 64 MB
Code length limit: 16 KB

#include <iostream>
using namespace std;
int main(){
    int store[6]={0};
    string input;
    cin>>input;
    for (int i = 0; i < input.length(); ++i) {
        switch (input[i]){
            case 'P':
                store[0]++;
                break;
            case 'A':
                store[1]++;
                break;
                break;
            case 'T':
                store[2]++;
                break;
            case 'e':
                store[3]++;
                break;
            case 's':
                store[4]++;
                break;
            case 't':
                store[5]++;
                break;
        }
    }
    while (store[0] !=0 ||store[1] !=0 ||store[2] !=0 ||store[3] !=0 ||store[4] !=0 ||store[5] !=0){
        if(store[0] !=0){
            cout<<"P";
            store[0]--;
        }
        if(store[1] !=0){
            cout<<"A";
            store[1]--;
        }
        if(store[2] !=0){
            cout<<"T";
            store[2]--;
        }
        if(store[3] !=0){
            cout<<"e";
            store[3]--;
        }
        if(store[4] !=0){
            cout<<"s";
            store[4]--;
        }
        if(store[5] !=0){
            cout<<"t";
            store[5]--;
        }
    }
    return 0;
}
Published 95 original articles · won praise 50 · views 8090

Guess you like

Origin blog.csdn.net/qq_43422111/article/details/104106012