之前写了一个C程序,用的VC6.0,在别人机子上运行显示线程错误。加上不兼容win7,还有fortran的原因,最终导致了我放弃了VC6.0.费劲周章安装上了VS2010.

算法虽然不算合理,至少基本没有Bug了。
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void main()
{
srand((unsigned)time(NULL));
int xx[3][3]={{0,-1,1},{1,0,-1},{-1,1,0}};
int p,c,n=3,x1=1,x2=1,x3=1,k;
float l=0.0,t;
printf("1,剪子;2,包袱;3,锤;0,退出:\n");
do
{
printf("请输入你的结果:");
scanf("%d",&p);
c=rand()%3+1;
t=c/3.0;
if(t<(1.0*x1/n))
c=3;
else
{
if(t>(1.0*(x2+x1)/n))
c=2;
else
c=1;
}
switch(p)
{
case 0:break;
case 1:k=xx[c-1][p-1];x1++;n++;break;
case 2:k=xx[c-1][p-1];x2++;n++;break;
case 3:k=xx[c-1][p-1];x3++;n++;break;
default:
printf("输入有误,请重新输入:\n");break;
}
switch(k)
{
case 1:printf("你赢了!\n"),l++;break;
case -1:printf("你输了!\n");break;
case 0:printf("平局!\n");break;
}
}while(p!=0);
printf("一共进行了%d场比赛,胜率为:%f.\n",n,l/n);
}

再次吐槽一下VC6.0,老掉牙的东西该抛弃了。。。

作者 hsyyf

《猜拳小程序及对VC6.0的一点牢骚。。。》有19条评论

回复 冷轩信 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注