早教吧作业答案频道 -->其他-->
我初学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++,做了个题运行不了...的网友还看了以下:
行列式求详解最好把答案拍下来计算行列式第一行111111n个1第二行22^2...2^n第三行33 2020-06-15 …
计算行列式第一行a1^na1^(n-1)*b1...a1*b1^(n-1)b1^n第二行a2^na 2020-07-09 …
计算n阶行列式D,其中Xi不等于0,i=1,2,...n,第一行为1,2,...n-1,n+Xn, 2020-07-19 …
女孩(n.)铅笔(n.)书(n.)橡皮(n.)箱;盒(n.)书包(n.)词典;字典(n.)老师;教师 2020-10-30 …
n阶行列式第一行1,2,3...n第二行2,3,4...1第三行3,4,5...2中间省略很多行,最 2020-11-01 …
该数表满足:(1)第n(n>1)行首尾两数均为n;(2)表中的递推关系类似杨辉三角;记第n(n>1) 2020-11-17 …
如图所示的三角形数阵中,满足:(1)第1行的数为1,(2)第n(n≥2)行首尾两数均为n,其余的数都 2020-11-20 …
S1输入nS2判断n是否等于2,若n=2,则执行S4:若n大于2则执行S3:S3依次从2到n-1检查 2020-11-20 …
SQL逐行递增怎么写第一行的值:1+1*n第二行的值:(1+1*n)+(1+1*n)*n第三行的值: 2020-12-15 …
感受;觉得(v.)严格的;严厉的(adj.)记住;记起(v.)遵循;跟随(v.)幸运;运气(n.)保 2020-12-15 …