给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按“GPLTGPLT....”这样的顺序输出,并忽略其它字符。当然,四种字符(不区分大小写)的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按GPLT的顺序打印,直到所有字符都被输出。
输入格式:
输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。
输出格式:
在一行中按题目要求输出排序后的字符串。题目保证输出非空。
输入样例:pcTclnGloRgLrtLhgljkLhGFauPewSKgt输出样例:
GPLTGPLTGLTGLGLL
#include<cstdio>
#include<string>
using namespace std;
int main(){
char s[10001];
int lg=0,lp=0,ll=0,lt=0;
scanf("%s",s);
for(int i = 0; s[i] != '\0'; i++){
if(s[i]=='G'||s[i]=='g')lg++;
else if(s[i]=='P'||s[i]=='p')lp++;
else if(s[i]=='L'||s[i]=='l')ll++;
else if(s[i]=='T'||s[i]=='t')lt++;
}
int a=lg>lp?lg:lp;
int b=ll>lt?ll:lt;
int c=a>b?a:b;
while(c--){
if(lg!=0){
printf("G");
lg--;
}
if(lp!=0){
printf("P");
lp--;
}
if(ll!=0){
printf("L");
ll--;
}
if(lt!=0){
printf("T");
lt--;
}
}
return 0;
}