【题解】UVA489 模拟
程序员文章站
2024-03-19 08:47:04
...
#include<cstdio>
#include<cstring>
const int N=110;
char s[N],s2[N];//答案是s,猜的是s2
int left,chance;//还需要猜left个位置,错chance次后就会输
int win,lose;//win==1赢lose==1输
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()
{
//freopen("in.txt","r",stdin);
int rnd;//第几局
while(scanf("%d%s%s",&rnd,s,s2)==3&&rnd!=-1)
{
printf("Round %d\n",rnd);
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)puts("You win.");
else if(lose)puts("You lose.");
else puts("You chickened out.");
}
return 0;
}
上一篇: UVa 201- Squares
推荐阅读
-
模拟抛物线
-
HCIE(3)——TCP DOS攻击模拟
-
HCIE(2)——ICMP攻击模拟
-
CSS:filter(滤镜)修饰父元素背景,影响子元素问题解决
-
ubuntu小技巧:小键盘模拟鼠标 博客分类: unix like ubuntunumlock小键盘
-
java Post 上传文件 博客分类: 上传文件 模拟HTTP文件上传
-
java Post 上传文件 博客分类: 上传文件 模拟HTTP文件上传
-
memcached缓存失效时的高并发访问问题解决 博客分类: 缓存系列 memcachedjava缓存问题并发
-
【转】Ubuntu 解压zip文件名乱码问题解决 博客分类: 随手摘记 ubuntuzip乱码
-
模拟json 假数据 博客分类: json 模拟json假数据