101.常胜将军

简介: 101.常胜将军
#include<stdio.h>
void main()
{
   int a=21,i;
   clrscr();
   puts("*****************************************************");
   puts("*            This is a Matchstick Taken Game.       *");
   puts("* There are 21 machsticks, two persons take them in *");
   puts("* turn. Each one each time takes 1 to 4 sticks. The *");
   puts("* one who takes the last stick will lose the game.  *");
   puts("*****************************************************");
   printf(" >> --------------- Game Begin ---------------------\n");
   while(a>0)
   {
      do{
         printf(" >> How many sticks do you wish to take(1~%d)?",a>4?4:a);
         scanf("%d",&i);
      }while(i>4||i<1||i>a);      /*接收正在确的输入*/
      if(a-i>0) printf(" >> %d stick left in the pile.\n",a-i);
      if((a-i)<=0)
      {
         printf(" >> You have taken the last stick.\n");
         printf(" >> ******* You lose! ******* \n");     /*输出取胜标记*/
         printf(" >> --------------- Game Over! ---------------------\n");
         break;
      }
      else
         printf(" >> Compute take %d stick.\n",5-i);    /*输出计算机取的子数*/
      a-=5;
      printf(" >> %d stick left in the pile.\n",a);
   }
   printf("\n Press any key to quit...");
   getch();
}
相关文章
|
5月前
|
存储 C++
基于C++的简易文件压缩与解压缩工具设计与实现
基于C++的简易文件压缩与解压缩工具设计与实现
152 3
|
5月前
|
存储 Kubernetes 容器
百度搜索:蓝易云【Kubernetes使用helm部署NFS Provisioner】
现在,你已经成功使用Helm部署了NFS Provisioner,并且可以在Kubernetes中创建使用NFS存储的PersistentVolumeClaim。
193 10
|
12月前
|
机器学习/深度学习
这图怎么画| 相关性热图+柱状图
这图怎么画| 相关性热图+柱状图
111 0
|
4月前
|
JavaScript Java 应用服务中间件
用白薅来的gitlab自带的gitlab-runner部署一个vue项目
用白薅来的gitlab自带的gitlab-runner部署一个vue项目
96 2
|
5月前
封装httpclient工具类
httpclient远程调用工具封装使用
|
5月前
|
Oracle 关系型数据库 数据库
PostgreSQL从入门到精通教程 - 第42讲:pg_rman部署与使用
PostgreSQL从入门到精通教程 - 第42讲:pg_rman部署与使用
160 1
|
11月前
|
NoSQL Redis
Redis集群中故障恢复
Redis集群中故障恢复
130 0
LeetCode 1221. 分割平衡字符串
在一个 平衡字符串 中,'L' 和 'R' 字符的数量是相同的。
53 0
|
存储 程序员 编译器
【C语言】你不知道的隐式类型转换规则
本文接着C语言中的操作符(万字详解)讲解隐式类型转换规则,还有没学操作符的老铁可以回头看看。 在 C 语言中,类型转换的方式一般可分为隐式类型转换和显示类型转换(也称为强制类型转换)。 其中隐式类型转换由编译器自动进行,不需要程序员干预。 隐式类型转换通常有两种情况:整形提升和算术转换。
398 0
|
IDE 网络安全 开发工具
在PyCharm中连接云端资源进行代码调试
通过PyCharm ToolKit连接ModelArts,您可在PyCharm中便捷地使用云端计算资源进行代码开发。
525 0
在PyCharm中连接云端资源进行代码调试