每组用例占一行,包含ZOJ三个字符。 1<=length<=100。
对于每组输入,请输出一行,表示按照要求处理后的字符串。 具体可见样例。
ZOJZOJOJ
#include<iostream> #include<string> using namespace std; int main() { string str; string str_r = ""; int count_z,count_o,count_j; while(cin>>str) { count_z = 0; count_o = 0; count_j = 0; str_r = ""; for(int i=0;i<str.length();i++) { if(str[i]==‘Z‘) count_z++; if(str[i]==‘O‘) count_o++; if(str[i]==‘J‘) count_j++; } int i,j,k; for(i=0,j=0,k=0;i<count_z||j<count_o||k<count_j;i++,j++,k++) { if(i<count_z) { str_r += "Z"; } else{ str_r += ""; } if(j<count_o) { str_r += "O"; } else{ str_r += ""; } if(k<count_j) { str_r += "J"; } else{ str_r += ""; } } cout<<str_r<<endl; } return 0; }
原文:https://www.cnblogs.com/ttzz/p/10348981.html