1975:ZOJ分数: 2
标签
题目描述
读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。
输入格式
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。
1<=length<=100。
输出
对于每组输入,请输出一行,表示按照要求处理后的字符串。
具体可见样例。
样例输入
ZZOOJJJ
ZOOOJJZOJ
ZZOJ
E
样例输出
ZOJZOJJ
ZOJZOJOJO
ZOJZ
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
int length,i,cz,co,cj;
while(getline(cin,str)){
if(str == "E")break;
cz=co=cj=0;
length = str.length();
for(i=0;i<length;++i){
if(str[i]=='Z')++cz;
else if(str[i]=='O')++co;
else ++cj;
}
while((cz!=0)||(co!=0)||(cj!=0)){
if(cz!=0){
cout<<"Z";
--cz;
}
if(co!=0){
cout<<"O";
--co;
}
if(cj!=0){
cout<<"J";
--cj;
}
}
cout<<endl;
}
return 0;
}