又是一个星期五, 开始发UVa的代码了啊!
比较忙的我没有太多练习题目的时间,所以就简简单单的找了一道水题来做,这道题没什么可以说的,所以就直接附上代码
地址在vjudge.net或UVa上
//yifei Wa //UVa 489 Hangman Judge #include <stdio.h> #include <string.h> //strlen() #define maxn 300 int t, chance; char com[maxn]; void guess(char a) { int fl = 0; for(int i = 0; i < strlen(com); i++) { if(a == com[i]) { com[i] = ' '; fl = 1; t--; } } if(!fl) chance--; } int main() { int r; while(scanf("%d", &r) != EOF && r != -1) { scanf("%s", com); t = strlen(com); char a; chance = 7; getchar(); for(;;) { a = getchar(); if(a == ' ' || !chance || !t) break; guess(a); //printf("%d %d ", chance, t); } //while while(a != ' ') a = getchar(); printf("Round %d ", r); if(!t) printf("You win. "); else if(!chance) printf("You lose. "); else printf("You chickened out. "); } return 0; }