大意:
电脑想个单词,玩家来猜。
玩家输入一个个字母,若答案里有这个字母,则显示该单词中所有该字母。
最终目标是显示答案所有字母。
猜错7次,死;

注意特殊条件:
1.玩家不断重复错误的字母,只算一次猜错。
2.如果答案是ans,读入了ansjklzxcv,这种情况算win的。虽然后面错误了7次,但游戏已经在猜出ans时提前结束了。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; const int maxalp=;
const int maxl=;
bool unguessed[maxalp];
bool alreadygussedwrong[maxalp];
int cnt;
char ans[maxl],guess[maxl];
int rnd;
int la,lg;
int ungcnt;
bool lose=false;
bool chickenedout=false;
bool insguess=false;
int main()
{
while(scanf("%d",&rnd))
{
if(rnd==-)break;
memset(unguessed,false,sizeof(unguessed));
memset(alreadygussedwrong,false,sizeof(alreadygussedwrong));
memset(ans,,sizeof(ans));
memset(guess,,sizeof(guess));
cnt=;
lose=false;
chickenedout=false;
insguess=false;
ungcnt=; printf("Round %d\n",rnd);
scanf("%s%s",ans,guess);
la=strlen(ans);
lg=strlen(guess);
for(int i=;i<la;i++)
if(!unguessed[ans[i]-'a'])
{
unguessed[ans[i]-'a']=true;
ungcnt++;
}
for(int i=;i<lg;i++)
{
int ch=guess[i]-'a';
if(unguessed[ch])
{
unguessed[ch]=false;
ungcnt--;
}
else if(!alreadygussedwrong[ch])
{
cnt++;
alreadygussedwrong[ch]=true;
}
if(!ungcnt)
{
printf("You win.\n");
insguess=true;
break;
}
if(cnt==)
{
printf("You lose.\n");
lose=true;
break;
}
}
if(!lose&&!insguess)
for(int i=;i<maxalp;i++)
if(unguessed[i])
{
printf("You chickened out.\n");
chickenedout=true;
break;
}
if(!lose&&!chickenedout&&!insguess)
printf("You win.\n");
} return ;
}

uva 489 Hangman Judge的更多相关文章

  1. UVa 489 Hangman Judge(字符串)

     Hangman Judge  In ``Hangman Judge,'' you are to write a program that judges a series of Hangman gam ...

  2. uva 489.Hangman Judge 解题报告

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. uva 489 Hangman Judge(水题)

    题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  4. UVA 489 Hangman Judge (字符匹配)

    题意:给一个字符串A,只含小写字符数个.再给一个字符串B,含小写字符数个.规则如下: 1.字符串B从左至右逐个字符遍历,对于每个字符,如果该字符在A中存在,将A中所有该字符删掉,若不存在,则错误次数+ ...

  5. uvaoj 489 - Hangman Judge(逻辑+写代码能力)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. Hangman Judge UVA - 489

    In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each gam ...

  7. UVa 489 HangmanJudge --- 水题

    UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...

  8. UVA.12169 Disgruntled Judge ( 拓展欧几里得 )

    UVA.12169 Disgruntled Judge ( 拓展欧几里得 ) 题意分析 给出T个数字,x1,x3--x2T-1.并且我们知道这x1,x2,x3,x4--x2T之间满足xi = (a * ...

  9. UVA 12169 Disgruntled Judge 扩展欧几里得

    /** 题目:UVA 12169 Disgruntled Judge 链接:https://vjudge.net/problem/UVA-12169 题意:原题 思路: a,b范围都在10000以内. ...

随机推荐

  1. php 资源

    ThinkPHP http://www.thinkphp.cn/ 小案例 http://www.helloweba.com/php.html Github上的PHP资源汇总大全 http://www. ...

  2. COG注释--转载

    http://blog.sina.com.cn/s/blog_670445240102uxwy.html 一 COG简介 COG,即Clusters of Orthologous Groups of ...

  3. React之JSX

    0.对于学习React,我们先来熟悉下JSX的语法, 下面的这些语法仅用于构建一个组件的标签模块,定义完成之后如果需要做演示,请附加以下代码: ReactDOM.render( element1, d ...

  4. Nginx模块之———— RTMP 模块的在线统计功能 stat 数据流数据的获取(不同节点则获取的方式不同)

    一.目前只有一个Live节点存在 单节点获取方式如下: public function getStreamByIp($outerIP, $streamName) { //查询录像模块的IP地址外网,根 ...

  5. Google C++ Style Guide

    Background C++ is one of the main development languages used by many of Google's open-source project ...

  6. sublime必备插件

    安装插件 安装插件时,先使用Ctrl+Shift+P(Tools→Command Palette...)打开控制面板,输入PackageControl  回车  显示. 选择Package Contr ...

  7. File API 读取上传的文件

    1, 在html 文档中,<input type="file"> 我们可以选择文件进行上传,但这时只能上传一个文件.如果加上multiple 属性,可以上传多个文件,上 ...

  8. ssh启动报错:org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect

    ssh项目启动报错: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection t ...

  9. 【WebGoat习题解析】Parameter Tampering->Bypass HTML Field Restrictions

    The form below uses HTML form field restrictions. In order to pass this lesson, submit the form with ...

  10. poj1753 Flip Game

    题意:4*4的正方形,每个格子有黑白两面,翻转格子使得4*4个格子显示全黑或全白,翻转要求:选中的那个格子,以及其上下左右相邻的格子(如果存在)要同时翻转.输出最小的达到要求的翻转次数或者Imposs ...