1032.ZOJ problem

Source: Internet
Author: User

Title Description:
read into a string, the string contains zoj three characters, the number is not necessarily equal, in the order of zoj output, when a character runs out, the rest is still in the order of zoj output.
The topic contains multiple sets of use cases, one for each group of use cases, containing zoj three characters, and the end of the input when the "E" is entered.
For each set of inputs, output a line that represents the string after processing as required.
A concrete example of the visible sample.
Sample input:
Sample output:

#include <iostream>#include<cstring>using namespacestd;intMain () {strings;  while(Getline (cin,s) && s!="E"){        intz=0, o=0, j=0;  for(intI=0; I<s.size (); i++){            if(s[i]=='Z') z++; Else if(s[i]=='O') o++; Else if(s[i]=='J') J + +; }         for(;z>0&& o>0&& j>0; z--, o--, j--) {cout<<"ZOJ"; }        if(z==0){             for(;o>0&& j>0; O--, j--) {cout<<"OJ"; }            if(o==0) {                 for(;j>0; j--) cout<<"J"; }            Else  for(;o>0; o--) cout<<"O"; }        if(o==0){             for(;z>0&& j>0; Z--, j--) {cout<<"ZJ"; }            if(z==0) {                 for(;j>0; j--) cout<<"J"; }            Else  for(;z>0; z--) cout<<"Z"; }        if(j==0){             for(;o>0&& z>0; O--, z--) {cout<<"ZO"; }            if(o==0) {                 for(;z>0; z--) cout<<"Z"; }            Else  for(;o>0; o--) cout<<"O"; } cout<<Endl; }        return 0;}

1032.ZOJ problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.