L1-023 输出GPLT
Statement
Metadata
- 作者: 陈越
 - 单位: 浙江大学
 - 代码长度限制: 16 KB
 - 时间限制: 150 ms
 - 内存限制: 64 MB
 
给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符。当然,四种字符(不区分大小写)的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按GPLT的顺序打印,直到所有字符都被输出。
输入格式
输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。
输出格式
在一行中按题目要求输出排序后的字符串。题目保证输出非空。
输入样例
输出样例
Solution
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int main() {
    string s;
    cin >> s;
    int len = s.size();
    int i;
    int a[4] = {0};
    for (i = 0; i < len; i++) {
        if (s[i] == 'G' || s[i] == 'g')
            a[0]++;
        else if (s[i] == 'P' || s[i] == 'p')
            a[1]++;
        else if (s[i] == 'L' || s[i] == 'l')
            a[2]++;
        else if (s[i] == 'T' || s[i] == 't')
            a[3]++;
    }
    while (a[0] || a[1] || a[2] || a[3]) {
        if (a[0]) {
            printf("G");
            a[0]--;
        }
        if (a[1]) {
            printf("P");
            a[1]--;
        }
        if (a[2]) {
            printf("L");
            a[2]--;
        }
        if (a[3]) {
            printf("T");
            a[3]--;
        }
    }
    cout << endl;
}
  Last update: May 4, 2022