早教吧作业答案频道 -->其他-->
我初学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
求哪位老大帮忙看看我做的题.
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;
}
程序是能运行的,亲自试验过才贴上去的(偶是负责人滴人),出现那样的错误是你复制的时候少了一个花括号,在最后.
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++,做了个题运行不了...的网友还看了以下:
设函数f(x)=1/x,数列{an}满足a1=a不等于0,且对于任意正整数n都有an+1=f(an 2020-05-13 …
高二数学排列组合,n个人换座位大神们帮帮忙n个人换座位,要求换后不能坐原来的位置,共有多少种换法! 2020-06-10 …
羽扇guān巾如题,是哪个guān 2020-06-15 …
请教等价无穷小替换的考研数学题n->无穷大时,lim[ntan(1/n)]^(n的平方)其中等价无穷 2020-10-31 …
关于一道排列的题N个人围绕一个圆桌坐,问有多少种作法?我认识是n!个坐法,可以答案说的是(n-1)! 2020-11-03 …
初一数学北师大版上册马上考试了,请问初一数学期末考试会考哪些题型,尤其应用题,会很难吗?(甘肃的)应 2020-11-06 …
已知数列{an}(此处n是下标,后面都是)中,a1=3,a(n+1)=2(a1+a2+……+an), 2020-11-19 …
高中语文诗歌题目一般会问哪种题,例如赏析一个句子中的某个字的妙处然后其中有它的答题的一个套路和技巧. 2020-11-24 …
基础词汇过关(英汉互译)1.愿意帮忙的;有用的adj.2.volunteern.3.社区n.4.问题 2020-12-26 …
一道初一数学问题n边形的内角和与一个外角的总和是1240度,求n.(目前还未学到一元二次方程,如果必 2021-02-21 …