惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
A
About on SuperTechFans
WordPress大学
WordPress大学
B
Blog
Martin Fowler
Martin Fowler
Jina AI
Jina AI
I
InfoQ
P
Proofpoint News Feed
小众软件
小众软件
S
SegmentFault 最新的问题
V
V2EX
B
Blog RSS Feed
量子位
大猫的无限游戏
大猫的无限游戏
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
MongoDB | Blog
MongoDB | Blog
美团技术团队

博客园 - laifangsong

请问福州哪里卖打折计算机图书,又可按原价开发票的? 关于目录访问的iis配置问题 福州招聘asp程序员 qq聊天的小秘密 吃鱼引发的问题和中国式管理 为什么点击flash链接到本页面,Request.Referrer将无法获得url来源 观察。总结 - 思想(一) 在csdn上看到奶牛问题,写了下算法 C#(1.1)邮件发送类,功能全面,调用灵活、方便 思考_070614 asp中JMail(4.4)发送邮件 单个文件上传类(可以自定义配置) iis6(win2003)中的aspnet_client和iis5,5.1(win2000,winxp)不一样,系统迁移时一定要注意。 看似诡异的session赋值错误 不错的分页存储过程(转) 矩阵相乘(c) 委托:两个例子(主人仆人、打游戏) 用递归算法求和为指定值N的所有组合 汉若塔问题(c)
取奇数游戏(c)
laifangsong · 2007-01-22 · via 博客园 - laifangsong


/*
该游戏规则如下: 操作者先输入一个奇数 N(<200)表示N个石
子. 设计算机为 A 方,操作者为 B 方, 双方轮流取石子,每次取1-3个. 最后取
到石子总数为奇数的一方获胜. 编制程序使计算机有较多的获胜机会,
*/

#include 

"stdio.h"
#include 
"conio.h"
main()
{
int total;
    
int p=0,c=0,pAdd,cAdd;

    printf(

"total=");
    scanf(
"%d",&total);

    printf(

"\n****begin****\n\n");do
    {
        
if(c%2==0)
        {
           
if(total>=3)
           {
              cAdd
=3;
           }
           
else if(total>=1)
           {
               cAdd
=1;
           }
        }
        
else
        {
            
if(total>=2)
            {
                cAdd
=2;
            }
            
else
            {
               cAdd
=1;
            }
        }
        total
-=cAdd;
        c
+=cAdd;
        printf(
"computer:%d\n",cAdd);
        
if(total==0break;
        printf(
"    %d leave.\n",total);

        printf(

"    person:");
        scanf(
"%d",&pAdd);
        
while(pAdd>3 || pAdd<1 || pAdd>total)
        {
            printf(
"    error! %d leave.again:",total);
            scanf(
"%d",&pAdd);
        }

        total

-=pAdd;
        p
+=pAdd;
        printf(
"person:%d\n",pAdd);

    }

while(total!=0);
    
    printf(
"\n****end****\n\n");

    outputResult(p,c);
    
    getch();
}

outputResult(_pNum,_cNum)
{

int pTag,cTag;

   printf(

"----result----\n");
   printf(
"person:%d\n",_pNum);
   printf(
"computer:%d\n",_cNum);

   pTag

=(_pNum%2!=0?1:0);
   cTag
=(_cNum%2!=0?1:0);

   printf(

"--------\n");
   
if((pTag||cTag) && !(pTag&&cTag))
   {
      
if(pTag)
      {
          printf(
"person win!");
      }
      
else
      {
          printf(
"computer win!");
      }

   }

else
   {
      printf(
"no one win!");
   }

    
}