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;
}