L1-023 输出GPLT
作者:
lvjj
,
2024-03-29 21:00:33
,
所有人可见
,
阅读 4
#include <bits/stdc++.h>
using namespace std;
map<string,int> m = {
{"G",0},
{"P",0},
{"L",0},
{"T",0}
};
int main(){
string str;
cin>>str;
for(int i=0;i<str.size();i++){
if(str[i]=='G'||str[i]=='g')m["G"]++;//在做字符串的某个字符的判断时,用的是字符类型char判断所以用''
if(str[i]=='P'||str[i]=='p')m["P"]++;
if(str[i]=='L'||str[i]=='l')m["L"]++;
if(str[i]=='T'||str[i]=='t')m["T"]++;
}
while(m["G"]!=0||m["P"]!=0||m["L"]!=0||m["T"]!=0){
if(m["G"]!=0){
cout<<"G";
m["G"]--;
}
if(m["P"]!=0){
cout<<"P";
m["P"]--;
}
if(m["L"]!=0){
cout<<"L";
m["L"]--;
}
if(m["T"]!=0){
cout<<"T";
m["T"]--;
}
}
return 0;
}