原创:
TC2.0以及gcc 编译通过
/*=======================================================
*Author :wacs5
*Date :20100601(YYYYMMDD)
*Function :剪刀石头布
*=======================================================*/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
char name[4][15]={"","scissors","stone","cloth"};
int x[2];
int i;
srand(time(NULL));
for (i=0;i<10;i++) /*10 times game*/
{
x[0]=1+rand()%3; /*generate a number from 1 to 3*/
x[1]=1+rand()%3; /*generate another number from 1 to 3*/
printf("A=%-12sB=%-12s\t",name[x[0]],name[x[1]]);
if (x[0]==x[1])
printf("draw\n"); /*和*/
else if (x[0]%3+1==x[1]) /*lost*/
printf("lost\n");
else /*win*/
printf("win\n");
}
getch();
return 0;
}
温馨提示:答案为网友推荐,仅供参考