This box has n ball, a, b two people take the ball in turn from the box, everyone can see how many other people have taken, also can see how many in the box, and both are very smart, will not make the wrong judgment.
We agree:
The number of balls that each person pulls out of the box must be: 1,3,7 or 8.
You cannot abstain from taking the ball on one side!
A take the ball first, then the two sides take the ball alternately, until the end is taken.
The one who is forced to get the last ball is the negative side (the loser)
Please program to determine if both sides do not judge the error, for a particular initial number of balls, a can win?
When the program runs, the data is obtained from standard input in the following format:
First an integer n (n<100), which indicates that there are n integers next. Then there are n integers, one for each row (integer <10000), representing the initial number of balls.
The program outputs n lines, which indicates the winning and losing situation of a (lost to 0, winning is 1).
For example, user input:
4
1
2
10
18
The program should output:
0
1
1
0
Attention:
Please carefully debug! Your program only has the chance to score when it can run the correct results!
The input data used in the grading is probably different from the instance data given in the quiz paper.
Please write all the functions in the same file, after debugging, deposited with the "candidate folder" corresponding to the title of the "answer. txt" can be.
The relevant engineering documents should not be copied into.
The source code cannot use APIs such as drawing, Win32API, interrupt invocation, hardware manipulation, or operating system-related.
STL class libraries are allowed, but not the class libraries of non-ANSI C + + standards such as MFC or ATL. For example, you cannot use the CString type (which belongs to the MFC class Library).
#include <iostream>using namespace Std;int a[101];int b[]={1,3,7,8};void cal () {a[0]=1;a[1]=0;a[2]=1;a[3]=0;a[4 ]=1;for (int i=5;i<101;i++) {int x=i;int flag, for (int j=0; j<4 && x-b[j]>0; j + +) {int k=0;flag=1; while (b[ K] <= X-b[j]) {if ( ! a[x-b[j]-b[k++]) {flag=0;break;} if (k==4) break;} A[i] = flag;if (flag) break;} }}int Main () {cal (); int N;cin>>n;while (n--) {int x;cin>>x;cout<<a[x]<<endl;}}
The third session of the Blue Bridge Cup in the first edition C + + Tenth