早教吧 育儿知识 作业答案 考试题库 百科 知识分享

我初学C++,做了个题运行不了.哪位老大帮忙看下错哪了求哪位老大帮忙看看我做的题.DescriptionStartswithtwounequalpositivenumbers(M,NandM>N)ontheboard.Twoplayersmoveinturn.Oneachmove,aplayerhastowrite

题目详情
我初学C++,做了个题运行不了.哪位老大帮忙看下错哪了
求哪位老大帮忙看看我做的题.
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
▼优质解答
答案和解析
楼主的gcd函数只有声明,没有定义,按照题目的意思,你的gcd应该是求最大公约数的吧.求最大公约数的辗转相除法如下:
int gcd(int a,int b)
{//辗转相除法求最大公约数
int r;
while(b != 0)
{
r = a % b;
a = b;
b = r;
}
return a;
}加上后从语法上说就没什么错误了.但是LZ的解法好像不对.应该有测试用例额,一并贴出来最好.下面这个你看一下.
#include
#include
int gcd(int a,int b)
{//辗转相除法求最大公约数
int r;
while(b != 0)
{
r = a % b;
a = b;
b = r;
}
return a;
}
int main()
{

int m, n;
int t;
scanf("%d%d",&m,&n);
if ( (m/gcd(m,n) )%2==0)
printf ("b");
else
printf ("a");
system("PAUSE");
return 0;
}

程序是能运行的,亲自试验过才贴上去的(偶是负责人滴人),出现那样的错误是你复制的时候少了一个花括号,在最后.