-
Description:
-
Determine whether a given string (containing only 'Z', 'O', and 'J') can be AC.
The AC rules are as follows:
1. zoj can communicate with each other;
2. If the string format is xzojx, it can also be AC, where X can be n 'O' or is empty;
3. If azbjc can be AC, azbojac can also be AC, where A, B, and C are n 'O' or empty;
-
Input:
-
The input contains multiple groups of test cases. Each line has a string that only contains 'Z', 'O', and 'J'. The length of the string is less than or equal to 1000.
-
Output:
-
For a given string, if the string can be AC, please output the string "accepted"; otherwise, please output "Wrong answer ".
-
Sample input:
-
zojozojoozoojoooozoojoooozoojozojooooozojozojoooo
-
Sample output:
-
AcceptedAcceptedAcceptedAcceptedAcceptedAcceptedWrong AnswerWrong Answer
-----------------------------------------------------
Ideas:
- First, determine whether the input is correct. 1. All input values are Z, O, and J. 2. Z and J can only have one input.
- When the input is correct, the number of O before Z is counted as a, the number of O between Z and J is counted as B, and the number of O after J is counted as C, which satisfies the condition that c = A × B, and B! = 0 accepted
-----------------------------------------------------
1 # include <stdio. h> 2 # include <string. h> 3 char l0 [1001]; 4 int main (INT argc, char const * argv []) 5 {6 int I, A, B, C; 7 int NZ, NJ; 8 int flag; 9 While (scanf ("% s", l0 )! = EOF) 10 {11 NZ = nj = Flag = 0; 12 for (I = 0; l0 [I]! = '\ 0'; I ++) 13 {14 if (l0 [I] = 'Z') 15 {16 NZ ++; 17 A = I; 18} 19 else if (l0 [I] = 'J') 20 {21 NJ ++; 22 B = I; 23} 24 else if (l0 [I]! = 'O') 25 flag = 1; 26 else27 continue;} 28 If (NZ! = 1 | NJ! = 1 | flag) // determine whether the input is correct 29 puts ("Wrong answer"); 30 else31 {32 c = strlen (L0)-B-1; B = b-a-1; // assume that Z is in front of J 33 If (C = a * B & B! = 0) // A is equal to B of C, and B! = 034 puts ("accepted"); 35 else36 puts ("Wrong answer"); 37} 38} 39 return 0; 40}
--------------------------------------------------------
Summary:
- All situations that need to be taken into account
- C ++ is more convenient than C Programming