1006.ZOJ problem

Source: Internet
Author: User

Title Description:
For a given string (containing only ' z ', ' o ', ' J ' three characters), determine if he can AC.

The rules for AC are as follows:
1. Zoj can ac;
2. If the string form is XZOJX, it can also be AC, where x can be n ' o ' or null;
3. If AZBJC can AC, then Azbojac can also be AC, where a,b,c is n ' o ' or empty;
Input:
The input contains multiple sets of test cases, each with a string that contains only ' Z ', ' o ', ' J ' three characters, and the string length is less than or equal to 1000.
Output:
For a given string, if you can ac then output the string "Accepted", otherwise output "wrong Answer".

Sample input:

Zoj
Ozojo
Ozoojoo
Oozoojoooo
Zooj
Ozojo
Oooozojo
Zojoooo
Sample output:

Accepted
Accepted
Accepted
Accepted
Accepted
Accepted
Wrong Answer
Wrong Answer

#include <iostream>using namespacestd;intMain () {strings;  while(cin>>s) {        BOOLflag=true; intPos=s.find ('Z'); inti;  for(i=0; i<pos;i++){            if(s[i]!='o') flag=false; }        intPos1=s.find ('J');  for(i=pos1+1; I<s.size (); i++){            if(s[i]!='o') flag=false; }        if((S.size ()-pos1-1)!=pos) flag=false; intnum=0;  for(i=pos+1; i<pos1;i++){            if(s[i]!='o') flag=false; Elsenum++; }        if(num==0) flag=false; if(flag) cout<<"Accepted"<<Endl; Elsecout<<"wrong Answer"<<Endl; }    return 0;}

1006.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.