uva489--Hangman Judge

(备注:还没有去UVA提交过,暂时设为私密)

//解题思路:猜中所有字母,win,猜错超过包括7次,lose,没有猜对所有字母,且还有机会但没有继续猜,视为chickened out

#include<iostream>
#include<string>
#include<cstring>
#include<bits\stdc++.h>

using namespace std;

const int maxn=100;
int chance;
int win;
int lose;
int rnd;
int num;//需要猜测的剩余位置数
string s1;
string s2;

void guess(char ch,int len1)
{
    int temp=0;
    for(int i=0;i<len1;i++){
        if(ch==s1[i]){
            s1[i]=' ';
            temp=1;
            num--;
        }
    }
    if(!temp){
        --chance;
    }
    if(!num){//猜中所有字母
        win=1;
    }
    if(!chance){//机会已用完
        lose=1;
    }
}

int main()
{
    while(cin>>rnd>>s1>>s2){
        if(rnd==-1){
            break;
        }
        int len1=s1.length();
        int len2=s2.length();
        win=0;
        lose=0;
        num=len1;
        chance=7;
        for(int i=0;i<len2;i++){
            guess(s2[i],len1);
            if(win||lose){
                break;
            }
        }
        cout<<"Round"<<' '<<rnd<<endl;
        if(win){
            cout<<"you win"<<endl;
        }else if(lose){
            cout<<"you lose"<<endl;
        }else{
            cout<<"you chickened out"<<endl;
        }
        cout<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值