时间复杂度: $O(n)$
#include<iostream>
using namespace std;
string s,res;
int st[4];
char str[4]={'G','P','L','T'};
int main(){
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]=='g'||s[i]=='G')st[0]++;
if(s[i]=='p'||s[i]=='P')st[1]++;
if(s[i]=='l'||s[i]=='L')st[2]++;
if(s[i]=='t'||s[i]=='T')st[3]++;
}
int t=0;
while(st[0]+st[1]+st[3]+st[2]){
if(st[t]){
res+=str[t];
st[t]--;
}
t=(t+1)%4;
}
cout<<res<<endl;
}