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

我初学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;
}

程序是能运行的,亲自试验过才贴上去的(偶是负责人滴人),出现那样的错误是你复制的时候少了一个花括号,在最后.
看了我初学C++,做了个题运行不了...的网友还看了以下:

这写了什么?老师叫了一名同学帮忙,他拿着铅笔对准老师手上口朝上的蛋壳,手一放,铅笔落到了蛋壳上,蛋  2020-05-12 …

帮个忙啊英语作文关于帮助的大致内容是说:有一个老妇在买完苹果回家时摔倒了,她的苹果也掉落在地上.一  2020-05-20 …

帮我写一篇过去式的文章60字左右.主要内容是:我国庆节过得很无聊.其他你们帮我编就可以了反正老师不  2020-06-04 …

请教一个英语表达法我帮了老外一个忙,老外说欠我一顿饭,我说帮你是我的荣幸,不要提晚饭,不然就见外了  2020-06-12 …

六语:选出没有语病的一句话下列语句中,没有语病的一项是()(2分)A老师慈母般的关怀,我一辈子终身  2020-06-27 …

谁能帮我回答问题:五年级下册第16课1,你从”水,爬上了老汉的胸膛”读出了什么?2,在小伙子被洪谁  2020-06-28 …

笑话折射人生哲理(2)在邮局大厅内,一位老太太走到一个中年人跟前,客气地说:“先生,请帮我在明信片  2020-07-08 …

出师表中“受任于败军之际,奉命于危难之间”说的是诸葛亮哪件事?老师开始问我,我给说成白帝城托孤了,老  2020-10-31 …

高智商的来帮我算下这道题!!!!!!!!!!!从前有一老头买了个水壶花了5元钱回家的路上遇见3个人这  2020-11-10 …

下列行为属于不负责任的行为的是A.李老师到学生家里家访B.小强将小亮考试作弊的事告诉了老师C.小梅骑  2020-11-13 …