欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【题解】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;
}
相关标签: 模拟