L1-023 输出GPLT

#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <cctype>

using namespace std;
#define maxn 3000


int main()
{
    int check[4]={0},mark=0;
    char b[4]={'G','P','L','T'};
    string s;cin >>s;
    transform(s.begin(),s.end(),s.begin(),::toupper);
    for (int i = 0; i < s.size(); i++)
        for (int k = 0; k <= 3; k++)
            if(s[i] == b[k])
                check[k]++;
    for (int i = 0; i <= 3; i++)if(check[i]) mark++;
    
    while(mark)
    {
        for (int i = 0; i <= 3; i++)
        if(check[i])
        {
            check[i]--;
            cout<<b[i];
            if(check[i] == 0)
            mark--;
        }
    }
    return 0;
}

posted on 2019-10-23 18:58  TigerDZ  阅读(114)  评论(0编辑  收藏  举报

导航