- 老师答疑区
- 帖子详情
【求救】第12周编程题“火柴游戏”
LapinBleu
发表于2016年12月03日
<p><strong><code class="brush:cpp;toolbar:false" style="width: 704px; height: 1992px;" >#include<stdio.h>
#define N 23
int main()
{
int move,left=N;
printf("Game start!\n");
printf("Note: the maximum number is 3\n");
while(left>0)
{
printf("Please enter the number of matches you are moving:\n");
scanf("%d",&move);
while((move!=1)&&(move!=2)&&(move!=3))
{
printf("The number you entered is wrong,please re-enter!\n");
printf("Please enter the number of matches you are moving:\n");
scanf("%d",&move);
}
printf("The number of matches you are moving is:%d\n",move);
if(left<=move)
{
if(left==move)
printf("The number of matches left is:%d\n",left-move);
printf("I'm sorry. You lost!\n");
break;
}
else
{
left=left-move;
printf("The number of matches left is:%d\n",left);
}
move=left%3+1;
if(left==left%3)
{
if(left==1)
move=1;
else move=move-2;
}
left=left-move;
printf("The number of matches that have been moved by the computer is:%d\n",move);
printf("The number of matches left is:%d\n",left);
if(left==0)
printf("Congratulations!You won!\n");
}
return 0;
}</code></strong><span style="font-size: 20px;" ><strong>花了两个多小时,仍然“用例1未通过”,有成功的人么?</strong></span></p>
2
回复