Created
February 25, 2013 17:53
-
-
Save caljim/5031771 to your computer and use it in GitHub Desktop.
剪刀石头布
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<time.h> | |
char hand[][10] = {"剪刀", "石头", "布"}; | |
int main() | |
{ | |
int computer, player, ret; | |
srand(time(NULL)); | |
while(1) { | |
computer = rand() % 3; | |
printf("玩家出手:\n"); | |
if(1 == scanf("%d", &player) && player < 3 && player >= 0) { | |
printf("C:%s,P:%s\n",hand[computer],hand[player]); | |
} | |
else | |
continue; | |
ret = computer - player; | |
if(ret == 0) | |
printf("平局\n"); | |
else if(ret == 1 || ret == -2) | |
printf("电脑胜利!\n"); | |
else | |
printf("玩家胜利!\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment