UVA Hangman Judge
英语太烂啊。
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.
1.两个字符窜进行判断,第二个字符窜是第一个字符窜的匹配,若第二个字符窜的字母能够完全匹配上第一个就win
2.若第一个字符窜的一个字母被判断过了,以后出现相同的字母无论是否匹配都不算数,而第二个字符窜的一个字符用过了,以后再用若能够匹配则不计数,若不能够匹配,错的计数就加一次
#include<stdio.h>
#include<string.h>
const int MAXN=1000;
int main()
{
int n,i,j,k;
int ans,flag;
int cas=1;
int len,len_word,len_guess;
char str1[MAXN],str2[MAXN];
while(scanf("%d",&n))
{
ans=flag=len_word=len_guess=0;
if(n==-1) break;
scanf("%s",str1);
scanf("%s",str2);
for (i=0;str1[i];i++)//去掉相同的
{
if(str1[i]!=1)
{
for (j=i+1;str1[j];j++)
{
if(str1[i]==str1[j]) str1[j]=1;
}
}
}
len=strlen(str1);
printf("Round %dn",n);
for (i=0;str1[i];i++)//计算有几个要猜字母
{
if(str1[i]!=1) len_word++;
}
for (i=0;str2[i];i++)
{
if(str2[i]==2) continue;//该字母已经踩过了
for (j=0;str1[j];j++)//猜对了
{
if(str2[i]==str1[j]) break;
}
if(j==len) ans++;//没猜对
else
{
len_guess++;
for (j=i+1;str2[j];j++)//无论猜对猜错都要清楚掉
{
if(str2[i]==str2[j]) str2[j]=2;
}
}
if(len_word==len_guess)
{
flag=1;
printf("You win.n");
break;
}
else if(ans==7)
{
flag=1;
printf("You lose.n");
break;
}
}
if(!flag) printf("You chickened out.n");
}
return 0;
}
- Java多线程详解3
- SpringMVC处理multipart请求.
- 一条简单的sql语句运行15天的原因分析(r5笔记第17天)
- 巧用flashback database实现灵活的数据回滚(r5笔记第16天)
- Spring Cache For Redis.
- css重写checkbox样式
- 通过shell脚本同时监控多个数据库负载(r5笔记第14天)
- Java 定时器 Timer 的使用.
- 通过shell脚本来统计段大小(r5笔记第14天)
- Linux下配置MySQL主从复制(r5笔记第13天)
- Final 关键字
- ArrayList 和 LinkedList的执行效率比较
- 关于consistent gets(r5笔记第12天)
- wait/notify 实现多线程交叉备份
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- SimpleCommand框架介绍以及简单使用(一)
- Android开发中使用achartengine绘制各种图表的方法
- Android开发中Listview动态加载数据的方法示例
- Android自定义实现顶部粘性下拉刷新效果
- Android开发使用自定义view实现ListView下拉的视差特效功能
- Android打造炫酷进度条效果
- Android开发实现自定义新闻加载页面功能实例
- Android下Activity间通信序列化过程中的深浅拷贝浅析
- Android升级支持库版本遇到的两个问题详解
- Android开发使用Drawable绘制圆角与圆形图案功能示例
- Android开发中自定义ProgressBar控件的方法示例
- Android 使用自定义RecyclerView控件实现Gallery效果
- Android开发中GridView用法示例
- React Native中Android物理back键按两次返回键即退出应用
- Android仿简书搜索框效果的示例代码