Computer Postgraduate examination of University of Zhejiang University-Zoj problem in 2010

Source: Internet
Author: User

Zoj problems
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2984 Accepted Submission (s): 906


Problem 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 line has a string containing only ' Z ', ' o ', ' J ' three characters, 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



Source

Computer Postgraduate examination of University of Zhejiang University-2010

HDU 3788
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;

Problem Analysis:
Satisfies the condition two: only need to appear between the z and the J one o can;
Satisfies the condition three: the assumption satisfies the condition two: Oozojoo, brings into the condition three a=oo,b=o,c=oo, according to the condition three executes once, then becomes oozoojoooo, carries on the execution once can obtain oozooojoooooo, can see according to the condition three each recursion pushes, The number of O in B plus 1,c is the number of O in a, and a recursive relationship is obtained:
The number of =x o in the number of o in A;
As long as the number of O in C =b the number of O *a in the number of O to get answers: Accepted;

/*view codeproblem:3788 (zoj problem)     Judge status:acceptedrunid:12763697    language:c++    Author:grantyuanc Ode Render status:rendered by hdoj C + + Code Render Version 0.01 beta*/#include <iostream> #include <cstdio> #inc lude<algorithm> #include <cstring> #include <cstring>using namespace Std;char s[1005];int Pz,pj,numa , Numb,numc;int Main () {  //  freopen ("1in.txt", "R", stdin);    Memset (s,0,sizeof (s));    while (~SCANF ("%s", s)) {        int l=strlen (s);        for (int i=0;i<l;i++)        {            if (s[i]== ' z ') pz=i+1;            if (s[i]== ' J ') pj=i+1;        }        NUMA=PZ-1;NUMB=PJ-PZ-1;NUMC=L-PJ;        if (numc==numa*numb&&pj-pz>1) printf ("accepted\n");        else printf ("wrong answer\n");        Memset (s,0,sizeof (s));    }    return 0;}


Computer Postgraduate examination of University of Zhejiang University-Zoj problem in 2010

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.