Skip to content

Instantly share code, notes, and snippets.

@caljim
Created February 25, 2013 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caljim/5031771 to your computer and use it in GitHub Desktop.
Save caljim/5031771 to your computer and use it in GitHub Desktop.
剪刀石头布
#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