PAT L1-023. 输出GPLT
题目链接
#include <stdio.h>
#include <string.h>
int
main() {
char gplt[10005];
int i, ng = 0, np = 0, nl = 0, nt = 0;
scanf("%s", gplt);
for( i = 0; i < strlen(gplt); i++ ) {
if( gplt[i] == 'g' || gplt[i] == 'G' ) {
ng++;
}
else if( gplt[i] == 'p' || gplt[i] == 'P' ) {
np++;
}
else if( gplt[i] == 'l' || gplt[i] == 'L' ) {
nl++;
}
else if( gplt[i] == 't' || gplt[i] == 'T' ) {
nt++;
}
}
while( ng || np || nl || nt ) {
if( ng != 0 ) {
printf("G");
ng--;
}
if( np != 0 ) {
printf("P");
np--;
}
if( nl != 0 ) {
printf("L");
nl--;
}
if( nt != 0 ) {
printf("T");
nt--;
}
}
printf("\n");
return 0;
}