【例题4-2 uva489】Hangman Judge

本文介绍了一道使用C++解决的竞赛编程题目,通过一轮轮的比拼,讲解了如何运用字符串处理技巧来判断游戏胜负的算法实现。文章提供了完整的代码示例,包括输入输出流程和关键函数的定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


在这里输入题意

【题解】


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

【代码】

#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;
}

转载于:https://www.cnblogs.com/AWCXV/p/9827021.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值