uva 489
程序员文章站
2022-06-06 20:40:45
...
题目链接:https://vjudge.net/problem/UVA-489
题目描述:
参考代码:
#include <stdio.h>
#include <string.h>
#define MAXSIZE 100
int left,chance;//还需要猜left个位置,错chance次之后就为输
char s[MAXSIZE],s2[MAXSIZE];
int win,lose;//win=1表示已经赢了,lose等于1i表示已经输了
void guess(char ch) {
int bad = 1;//作一个标记
for(int i = 0; i < strlen(s); i++)
if(s[i]==ch) {
left--;
s[i] = ' ';
bad = 0;
}
if(bad) --chance;
if(!chance) lose = 1;
if(!left) win = 1;
}
/*主函数*/
int main() {
int Round;
while(scanf("%d%s%s",&Round,s,s2)==3 && Round!=-1) {
printf("Round %d\n",Round);
win = lose = 0;//初始化
left = strlen(s);
chance = 7;
for(int i = 0; i < strlen(s2); i++) {
guess(s2[i]);//猜一个字母
if(win||lose) break;//检查现在的输赢状态,如果确定了,跳出循环
}
//根据结果进行输出
if(win) printf("You win.\n");
else if(lose) printf("You lose.\n");
else printf("You chickened out.\n");
}
return 0;
}
上一篇: 希尔排序
下一篇: 利用JNI调用c++函数
推荐阅读
-
团体队列 UVA540 Team Queue
-
丑数(Ugly Numbers, UVa 136)
-
破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
-
集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096)
-
唯一的雪花(Unique snowflakes,UVa 11572)滑动窗口+set
-
[UVA - 11584] Partitioning by Palindromes dp预处理
-
UVA227-Puzzle
-
UVA 442 Matrix Chain Multiplication ( stack 应用)
-
UVA 136 - Ugly Numbers(优先队列 + 集合)
-
(UVa 136) Ugly Numbers(丑数的生成+整数分解定理+优先队列)