题目描述:
读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。
输入:
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。
1<=length<=100。
输出:
对于每组输入,请输出一行,表示按照要求处理后的字符串。
具体可见样例。
样例输入:
ZZOOOJJJ
ZZZZOOOOOJJJ
ZOOOJJ
E
样例输出:
ZOJZOJOJ
ZOJZOJZOJZOO
读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。
输入:
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。
1<=length<=100。
输出:
对于每组输入,请输出一行,表示按照要求处理后的字符串。
具体可见样例。
样例输入:
ZZOOOJJJ
ZZZZOOOOOJJJ
ZOOOJJ
E
样例输出:
ZOJZOJOJ
ZOJZOJZOJZOO
ZOJOJO
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string str;
while(cin >> str)
{
if(str == "E")
break;
int count1 = count(str.begin(),str.end(),'Z');
int count2 = count(str.begin(),str.end(),'O');
int count3 = count(str.begin(),str.end(),'J');
int total_count = count1 + count2 + count3;
for(int i = 0; i < total_count; ++i)
{
if(count1-- > 0)
{
cout << 'Z';
}
if(count2-- > 0)
{
cout << 'O';
}
if(count3-- > 0)
{
cout << 'J';
}
}
cout << endl;
}
return 0;
}