489 - Hangman Judge
2016-01-27 21:02
239 查看
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=430&mosmsg=Submission+received+with+ID+16764260
#include<stdio.h> #include<stdlib.h> #include<string.h> int left, chance; int win, lost; char ans[101], in[101]; void guess(char c); int main() { int T = 0, i = 0; while (scanf("%d%s%s", &T, ans, in) == 3 && T != -1) { win = lost = 0; chance = 7; left = strlen(ans); for (i = 0; i < strlen(in); i++) { guess(in[i]); if (win || lost) break; } printf("Round %d\n", T); if (win) printf("You win.\n"); else if (lost) printf("You lose.\n"); else printf("You chickened out.\n"); } return 0; } void guess(char c) { int i = 0, found = 0; for (i = 0; i < strlen(ans); i++) { if (c == ans[i]) { ans[i] = ' '; found = 1; left--; } } if (!found) chance--; if (!left) { win = 1; return; } else if (!chance) { lost = 1; return; } return; }
相关文章推荐
- 依据二度人脉推荐好友sql
- PHP——转义字符
- 新手学JavaScript(四)----CheckBox全选与全不选
- socket接收消息拼接
- Android之应用程序内存优化
- 如何管理自己?
- 利用zbar实现条形码扫描
- page指令的errorPage属性的用法
- android内存泄露分析
- utf8和utf-8的区别
- Android NDK 配置
- setTimeout实现动画的黄金优化法则
- js中(function(){…})()立即执行函数写法理解
- Git学习心得
- 重构-tips
- new的三种形态
- mybatis中的坑
- 指针
- 并查集模板、
- 主机宝等主机面板不能跨站访问文件,不能访问父路径文件问题