UVa 489 - Hangman Judge
Time limit: 3.000 seconds
In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follows:
- The contestant tries to solve to puzzle by guessing one letter at a time.
- Every time a guess is correct, all the characters in the word that match the guess will be ``turned over.'' For example, if your guess is ``o'' and the word is ``book'', then both ``o''s in the solution will be counted as ``solved.''
- Every time a wrong guess is made, a stroke will be added to the drawing of a hangman, which needs 7 strokes to complete. Each unique wrong guess only counts against the contestant once.
______ | | | O | /|\ | | | / \ __|_ | |______ |_________|
- If the drawing of the hangman is completed before the contestant has successfully guessed all the characters of the word, the contestant loses.
- If the contestant has guessed all the characters of the word before the drawing is complete, the contestant wins the game.
- If the contestant does not guess enough letters to either win or lose, the contestant chickens out.
Your task as the ``Hangman Judge'' is to determine, for each game, whether the contestant wins, loses, or fails to finish a game.
Input
Your program will be given a series of inputs regarding the status of a game. All input will be in lower case. The first line of each section will contain a number to indicate which round of the game is being played; the next line will be the solution to the puzzle; the last line is a sequence of the guesses made by the contestant. A round number of -1 would indicate the end of all games (and input).
Output
The output of your program is to indicate which round of the game the contestant is currently playing as well as the result of the game. There are three possible results:
You win. You lose. You chickened out.
Sample Input
1 cheese chese 2 cheese abcdefg 3 cheese abcdefgij -1
Sample Output
Round 1 You win. Round 2 You chickened out. Round 3 You lose.
#include<stdio.h> #include<string.h> int main() { int i = 0, j, n, len, flag[101]; char ch[101], chance, t; while(scanf("%d", &n) != EOF && n != -1) { memset(ch, 0, sizeof(ch)); memset(flag, 0, sizeof(flag)); scanf("%s", ch); getchar(); len = strlen(ch); for(i=0; i<=7;) { t = 0; chance = getchar(); if(i == 7 && chance != '\n') continue; else if(chance == '\n') break; for(j=0; j<len; j++) { if(ch[j] == chance) { t = 1; flag[j] = 1; } } if(t == 0) i++; } printf("Round %d\n", n); for(j=0; j<len && flag[j] == 1; ++j); if(j<len) {if(i != 7)printf("You chickened out.\n"); else printf("You lose.\n"); }else printf("You win.\n"); } return 0; }
解题报告:
这题可以说是简单题,分情况写代码,题目背景可以忽略,做这题的时间差不多用了我两个小时,仅仅是因为考虑情况不周,WA了两次,
再者因Valladolid的OJ不允许输入注释掉的语句“//”CE了两次。题目如此简单,为何耗时如此之多,我想原因是:1> 看到题目觉得是简单题,
不像其他题要想一段时间才有思路,但没想到就算一简单题无明确的思路去做只会手忙脚乱,更不用说要达到一次通过的情况了。2>未摒弃急躁的心,
既然想一次AC,为何还要用在线判题,MoreIP的是题目做得太少了

更多内容请关注个人微信公众号 物役记 (微信号:materialchains)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?