1 /*Problem Description 2 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。 3 Input 4 题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。 5 1<=length<=100。 6 7 Output 8 对于每组输入,请输出一行,表示按照要求处理后的字符串。 9 具体可见样例。 10 Sample Input 11 ZZOOOJJJ 12 ZZZZOOOOOJJJ 13 ZOOOJJ 14 E 15 Sample Output 16 ZOJZOJOJ 17 ZOJZOJZOJZOO 18 ZOJOJO*/ 19 #include<stdio.h> 20 #include<string.h> 21 int main() 22 { 23 char s[101]; 24 while(1) 25 { 26 int i,j,a=0,b=0,c=0,n,max; 27 scanf("%s",s); 28 getchar(); 29 if(s[0]==‘E‘)break; 30 n=strlen(s); 31 for(i=0;i<n;i++) 32 { 33 if(s[i]==‘Z‘) 34 a+=1; 35 if(s[i]==‘O‘) 36 b+=1; 37 if(s[i]==‘J‘) 38 c+=1; 39 } 40 max=((a>b) ? a:b) > c ? ((a>b) ? a:b) : c; 41 for(j=0;j<max;j++) 42 { 43 if(j<a) 44 printf("Z"); 45 if(j<b) 46 printf("O"); 47 if(j<c) 48 printf("J"); 49 } 50 printf("\n"); 51 } 52 return 0; 53 }
原文:http://www.cnblogs.com/a604378578/p/3550574.html