ZOJ
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2160 Accepted Submission(s): 1494
Total Submission(s): 2160 Accepted Submission(s): 1494
Problem Description
读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。
Input
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。
1<=length<=100。
1<=length<=100。
Output
对于每组输入,请输出一行,表示按照要求处理后的字符串。
具体可见样例。
具体可见样例。
Sample Input
ZZOOOJJJ ZZZZOOOOOJJJ ZOOOJJ E
Sample Output
ZOJZOJOJ ZOJZOJZOJZOO ZOJOJO#include<stdio.h> #include<string.h> int main() { char a[100]; int i,j,k,count1,count2,count3; while(gets(a)) { if(a[0]=='E') return 0; k=strlen(a); count1=0; count2=0; count3=0; for(i=0;i<k;i++) { if(a[i]=='Z') count1++; if(a[i]=='O') count2++; if(a[i]=='J') count3++; } while(count1>0||count2>0||count3>0) { if(count1>0) { printf("Z"); count1--; } if(count2>0) { printf("O"); count2--; } if(count3>0) { printf("J"); count3--; } } printf("\n"); } return 0; }思路先统计ZOJ的数量,然后在用while语句按ZOJ挨个输出


433

被折叠的 条评论
为什么被折叠?



