作者在 2011-09-02 09:48:39 发布以下内容
/*
时间:2011年9月2日9:45:11
目的:一个小游戏,论坛上看到的题目,觉得有趣,试试自己能不能编出来
功能:16个硬币,玩家和电脑轮流拿,每人每次只能拿1、2或4枚,最后一枚谁拿走谁算输
*/
# include <stdio.h>
int main (void)
{
int s=16;
int n;
char ch;
do
{
while (s > 0)
{
while (1)
{
if (s >= 4)
printf("轮到您拿取硬币了,还剩余%d枚硬币,您可以拿取1枚、2枚或4枚\n",s);
else if (s >= 2)
printf("轮到您拿取硬币了,还剩余%d枚硬币,您可以拿取1枚或2枚\n",s);
else
printf("轮到您拿取硬币了,还剩余%d枚硬币,您只能拿取1枚\n",s);
scanf("%d",&n);
if ((n ==1 || n==2 || n==4) && s-n>=0)
{
s -= n;
break;
}
else
printf("不许耍赖皮!\n\n");
}
if (s == 0)
{
printf("\n您输了\n");
continue;
}
switch (n)
{
case 1:
{
printf("电脑拿取了2枚硬币\n");
s -= 2;
break;
}
case 2:
{
printf("电脑拿取了1枚硬币\n");
s -= 1;
break;
}
case 4:
{
printf("电脑拿取了2枚硬币\n");
s -= 2;
break;
}
}
printf("\n");
}
printf("\n再玩一次?(Y/N)");
scanf(" %c",&ch);
s = 16;
printf("\n");
} while ('y'== ch || 'Y'==ch);
return 0;
}
时间:2011年9月2日9:45:11
目的:一个小游戏,论坛上看到的题目,觉得有趣,试试自己能不能编出来
功能:16个硬币,玩家和电脑轮流拿,每人每次只能拿1、2或4枚,最后一枚谁拿走谁算输
*/
# include <stdio.h>
int main (void)
{
int s=16;
int n;
char ch;
do
{
while (s > 0)
{
while (1)
{
if (s >= 4)
printf("轮到您拿取硬币了,还剩余%d枚硬币,您可以拿取1枚、2枚或4枚\n",s);
else if (s >= 2)
printf("轮到您拿取硬币了,还剩余%d枚硬币,您可以拿取1枚或2枚\n",s);
else
printf("轮到您拿取硬币了,还剩余%d枚硬币,您只能拿取1枚\n",s);
scanf("%d",&n);
if ((n ==1 || n==2 || n==4) && s-n>=0)
{
s -= n;
break;
}
else
printf("不许耍赖皮!\n\n");
}
if (s == 0)
{
printf("\n您输了\n");
continue;
}
switch (n)
{
case 1:
{
printf("电脑拿取了2枚硬币\n");
s -= 2;
break;
}
case 2:
{
printf("电脑拿取了1枚硬币\n");
s -= 1;
break;
}
case 4:
{
printf("电脑拿取了2枚硬币\n");
s -= 2;
break;
}
}
printf("\n");
}
printf("\n再玩一次?(Y/N)");
scanf(" %c",&ch);
s = 16;
printf("\n");
} while ('y'== ch || 'Y'==ch);
return 0;
}