九度OnlineJudge之1032:ZOJ

题目描述:
读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。
输入:
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。
1<=length<=100。
输出:
对于每组输入,请输出一行,表示按照要求处理后的字符串。
具体可见样例。
样例输入:
ZZOOOJJJ
ZZZZOOOOOJJJ
ZOOOJJ
E
样例输出:
ZOJZOJOJ
ZOJZOJZOJZOO
ZOJOJO

//晚上太无聊了,做了一题水题

#include <iostream>
#include <string>

using namespace std;

int main()
{
	string str;
	while(cin>>str,str!="E")
	{

		int a=0,b=0,c=0;
		for(string::iterator it=str.begin();it!=str.end();++it)
		{
			if(*it=='Z') ++a;
			if(*it=='O') ++b;
			if(*it=='J') ++c;                                        
		}
	   int total = a+b+c;
	   for (int i=0;i<total;++i)
	   {
		   if(a>0)
		   {
			   cout<<"Z";
			   --a;
		   }
		   if(b>0)
		   {
		        cout<<"O";
				--b;
		   }
		   if (c>0)
		   {
			   cout<<"J";
			   --c;
		   }
	   }

				cout<<endl;                    
	}
	//system("PAUSE");
	return 0;
}



posted on 2013-09-24 21:49  爱你一万年123  阅读(183)  评论(0编辑  收藏  举报

导航