L1-023 输出GPLT C++

题目地址```

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[150]={0}; //我们只需要定义一个数组 因为字母值得大小都在127之内
    //用来记录出现字母的次数即可
    char c;
    while(scanf("%c",&c)!=EOF)  //EOF = -1 
    {
        c=toupper(c);  //toupper:将所有字母转换为大写
        a[c]++;
    }
    while(a['G']||a['P']||a['L']||a['T'])
    {
        if(a['G'])
        cout<<'G',a['G']--;
         if(a['P'])
        cout<<'P',a['P']--;
         if(a['L'])
        cout<<'L',a['L']--;
         if(a['T'])
        cout<<'T',a['T']--;
    }
}

上一篇:JZ-023-二叉搜索树的后序遍历序列


下一篇:L1-023 输出GPLT