#include <stdio.h>
#include <stdlib.h>
#include<sys/types.h>
#include<sys/timeb.h>
main()
{
loop:
printf("欢迎来玩石头剪刀布,请使用键盘输入,0代表石头,1代表剪刀,2代表布。\n******************************************************\n")
int x,com,user
unsigned int seedVal
struct timeb timeBuf
ftime(&timeBuf)
seedVal=((((unsigned int)timeBuf.time&0xFFFF)+
(unsigned int)timeBuf.millitm)^
(unsigned int)timeBuf.millitm)
srand((unsigned int)seedVal)
x=rand()
com=x%3
scanf("%d",&user)
if(user>2)
printf("您的输入有误,请输入0、1、2中任意一个数字\n")
else
{
if(com==0)
{
if(user==0) printf("平手\n")
if(user==1) printf("输了\n")
if(user==2) printf("赢了\n")
}
if(com==1)
{
if(user==0) printf("赢了\n")
if(user==1) printf("平手\n")
if(user==2) printf("输了\n")
}
if(com==2)
{
if(user==0) printf("输了\n")
if(user==1) printf("赢了\n")
if(user==2) printf("平手\n")
}
}
goto loop
}
player = int(input(“请出拳 石头(1)/剪刀(2)/布(3)”))
computer = 1
if((player == 1 and computer == 2) or
(player == 2 and computer == 3) or
(player == 3 and computer == 1)):
print(“欧耶!电脑弱爆了!”)
elif player == computer:
print(“心有灵犀,再来一盘!”)
else:
print(“不行,我要和你决战到天明!”)
执行的时候,第一行一定要单独复制,因为你需要输入一个数值
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)