C++编程 求救

来源:百度知道 编辑:UC知道 时间:2024/05/22 06:47:05
Description

Starts with two unequal positive numbers (M,N and M>N) on the board. Two players move in turn. On each move, a player has to write on the board a positive number equal to the difference of two numbers already on the board; this number must be new, i.e., different from all the numbers already on the board. The player who cannot move loses the game. Should you choose to move first or second in this game?

According to the above rules, there are two players play tihs game. Assumptions A write a number on the board at first, then B write it.

Your task is write a program to judge the winner is A or B.

Input

Two unequal positive numbers M and N , M>N (M<1000000)

Output

A or B

Sample Input

3 1

Sample Output

A

这是某个学校的ACM的题目吧?以下是我刚刚写的,不知有没有理解错。
#include <iostream.h>
bool WriteToBuf(int nSourceNum,int* pBuf,int nBufLen,int nNull)
{
bool bWrited=false;
for(int i=0;i<nBufLen;i++)
{
if((pBuf[i]!=nSourceNum) && (pBuf[i]==nNull))
{
pBuf[i]=nSourceNum;
bWrited=true;
break;
}
else continue;
}
return bWrited;
}
void main()
{
cout<<"enter M and N:(M>N) ";
cout<<endl;
int M,N;
cin>>M>>N;
if(N>M)
{
cout<<"error! M must be larger than N"<<endl;
return;
}
int* buf=new int[M];

if(buf==NULL)
{
cout<<"mem error!"<<endl;
return;
}
for(int i=0;i<M;i++) buf[i]=-1;
buf[0]=M;
buf[1]=N;
int index=2;
int act_count=0;
bool res=false;
while(buf[M-1]==-1)
{
f