zoukankan      html  css  js  c++  java
  • 题目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 count[3]={0};
    		int k=str.length();
    		for(int i=0;i<k;i++)
    		{
    			if(str[i]=='Z')
    				count[0]++;
    			else if(str[i]=='O')
    				count[1]++;
    			else if(str[i]=='J')
    				count[2]++;
    		}
    		int min=count[0],max=count[0];
    		for(int i=1;i<3;i++)
    		{
    			if(min>count[i])min=count[i];
    			else if(max<count[i])max=count[i];
    		}
    		for(int i=0;i<min;i++)
    			cout<<"ZOJ";
    		count[0]-=min;
    		count[1]-=min;
    		count[2]-=min;
    		for(int i=0;i<max-min;i++)
    		{
    			if(count[0]-->0)cout<<'Z';
    			if(count[1]-->0)cout<<'O';
    			if(count[2]-->0)cout<<'J';
    		}
    		cout<<endl;
    
    	}
    	return 0;
    }


    极简,专注,速度,极致
  • 相关阅读:
    XMU1349 xmu_1349
    字符串排序
    linux磁盘文件与目录管理系统(2)
    poj 3667 Hotel
    poj 3468 A Simple Problem with Integers
    linux文与目录管理
    Linux的磁盘与文件管理系统(1)
    hdu 1698 Just a Hook
    poj3225 Help with Intervals
    poj 2886Who Gets the Most Candies?
  • 原文地址:https://www.cnblogs.com/simplelifestyle/p/3761883.html
Copyright © 2011-2022 走看看