【例题4-2 uva489】Hangman Judge

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


水题。
中间就赢了算赢。(重复说,算错

【代码】

#include <bits/stdc++.h>
using namespace std;

int _round;
string s1,s2;
int cnt[300];

int ok(string s){
    int cur = 0;
    for (int i = 0;i < (int)s.size();i++){
        int temp = s[i]-'a';
        if (cnt[temp]==0){
            cur++;
            if (cur==7)
                return 0;
        }else{
            cnt[temp] = 0;
        }
        bool win = 1;
        for (int j = 0;j < 26;j++) if (cnt[j]==1) win = 0;
        if (win) return 1;
    }
    return -1;
}

int main()
{
    //freopen("/home/ccy/rush.txt","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0);
    while (cin >>_round){
        for (int i = 0;i < 26;i++) cnt[i] = 0;
        if (_round==-1) break;
        cout<<"Round "<<_round<<endl;
        cin >> s1;
        for (int i = 0;i < (int)s1.size();i++) cnt[s1[i]-'a']=1;
        cin >> s2;
        int ju = ok(s2);
        if (ju==0)
            cout<<"You lose."<<endl;
        else if(ju==1)
            cout<<"You win."<<endl;
            else cout<<"You chickened out."<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/AWCXV/p/9827021.html