天天看点

PAT 乙级 1043 输出PATest (20分)

1043 输出PATest (20分)

给定一个长度不超过 104 的、仅由英文字母构成的字符串。请将字符重新调整顺序,按 PATestPATest… 这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按 PATest 的顺序打印,直到所有字符都被输出。

输入格式:

输入在一行中给出一个长度不超过 104 的、仅由英文字母构成的非空字符串。

输出格式:

在一行中按题目要求输出排序后的字符串。题目保证输出非空。

输入样例:

#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;
}