Nine degree OJ topic 1006:zoj problem

Source: Internet
Author: User
Tags printf

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

Two. Topic analysis

After the comprehensive analysis of the conditions of the problem, we can get AC condition is NA*NB=NC, at the same time should pay attention to nb>0 this condition, because ZJ is WA's.

Deeply tortured by this problem, in nine degrees has been in all kinds of WA, although the code on the Hdu AC, has been looking for Ah, OK, the original is the input method is wrong, the while (Get (str)) replaced while (scanf ("%s", str)!=eof) on it, Simply cry dizzy, this is what ghost, hope to see you master can answer the difference, always thought the two are equal ....

Three. Code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 1002
int Main ()
{
    int i,start,end,mid;
    Char Str[max];

    Freopen ("1006.txt", "R", stdin);

    while (scanf ("%s", str)!=eof)
    {
        start=0;
        mid=0;
        end=0;

        i=0;

        while (str[i]== ' o ')
	{
		start++;
		i++;
	}

        if (str[i]!= ' z ')
	{
		printf ("Wrong answer\n");
		Continue;
	}

        i++;

	while (str[i]== ' o ')
	{
		mid++;
		i++;
	}

	if (str[i]!= ' J ')
	{
		printf ("Wrong answer\n");
		Continue;
	}

	i++;
	while (str[i]== ' o ')
	{
		end++;
		i++;
	}
	if (str[i]!= ')
	{
		printf ("Wrong answer\n");
		Continue;
	}

	if (end==start*mid&&mid>0)
            printf ("accepted\n");
        else
            printf ("Wrong answer\n");
    }
    return 0;
}



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.