L1-023. Output GPLT, l1-023 output gplt
A string of no more than 10000 English letters. Please re-adjust the character order, output in the order of "GPLTGPLT...", and ignore other characters. Of course, the numbers of the four types of characters (case-insensitive) are not necessarily the same. If a certain character has been output, the remaining characters are still printed in the GPLT order, until all characters are output.
Input Format:
Enter a non-empty string consisting of letters and letters that cannot exceed 10000 characters in a row.
Output Format:
Output the sorted string in one row according to the question requirement. Ensure that the output of the question is not empty.
Input example:
pcTclnGloRgLrtLhgljkLhGFauPewSKgt
Output example:
GPLTGPLTGLTGLGLL
Time Limit: 150 ms memory limit: 65536 kB code length limit: 8000 B Judgment program Standard author Chen Yue Note: Subject requirements, case insensitive, therefore, you must add a str [I] = a [j] + 'a'-'A' to determine the condition, that is, the ASCII gap between upper-case letters and lower-case letters.
#include <stdio.h>#include <stdlib.h>#include <string.h>#define N 10001int GetMax(int c[]){ int i; int max = 0; for(i = 0; i < 4; i++) { if(c[i] > max) max = c[i]; } return max;}int main(){ char str[N+1]; char a[5] = {'G', 'P', 'L', 'T'}; int b[4] = {0}; int i; int j; int max; scanf("%s", str); for(i = 0; i < strlen(str); i++) { for(j = 0; j < 4; j++) { if(str[i] == a[j] || str[i] == a[j] +'a' - 'A') { b[j]++; } } } max = GetMax(b); while(max != 0) for(i = 0; i < 4; i++) { if(b[i] != 0) { printf("%c", a[i]); b[i]--; max = GetMax(b); } } return 0;}