UVa489

猜完了要跳出来= =wa了好多发

#pragma warning(disable:4996)
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<time.h>
#include<map> 
#include<set>
#include<sstream>
#include<cassert>

using namespace std;
const int INF = 0x3f3f3f3f;


void guess(char * str1, char * str2)
{
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    int sum = 0;
    int left = len1;
    for (int i = 0;i<len2;i++)
    {
        int bad = 1;
        char temp = str2[i];
        for (int j = 0;j<len1;j++)
        {
            if (temp == str1[j])
            {
                left--;
                str1[j] = ' ';
                bad = 0;
            }
        }
        if (bad)
            sum++;
        if (sum == 7||!left)
            break;
    }
    if (sum < 7 && !left)
        cout << "You win." << endl;
    else if (sum ==7)
        cout << "You lose." << endl;
    else 
        cout << "You chickened out." << endl;
}
int main()
{
    int n;
    while (cin >> n)
    {
        char str1[500], str2[500];
        if (n == -1)
            return 0;
        cout << "Round " << n << endl;
        cin >> str1;
        cin >> str2;
        guess(str1, str2);
    }
    return 0;
}

刘汝佳大神的

#pragma warning(disable:4996)
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<time.h>
#include<map> 
#include<set>
#include<sstream>
#include<cassert>

using namespace std;
const int INF = 0x3f3f3f3f;


int lf, chance;
int win, lose;

void guess(char * str1, char * str2)
{
    lf = strlen(str1);
    win = lose = 0;
    chance = 7;
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    for (int i = 0;i <len2;i++)
    {
        char ch = str2[i];
        int bad = 1;
        for (int j = 0;j < len1;j++)
        {
            if (str1[j] == ch)
            {
                lf--;
                str1[j] = ' ';
                bad = 0;
            }
        }
        if (bad)--chance;
        if (!chance)lose = 1;
        if (!lf)win = 1;
        if (win || lose)
            break;
    }
    if (win)
        cout << "You win." << endl;
    else if (lose)
        cout << "You lose." << endl;
    else
        cout << "You chickened out." << endl;
}
int main()
{
    int n;
    while (cin >> n)
    {
        char str1[500], str2[500];
        if (n == -1)
            return 0;
        cout << "Round " << n << endl;
        cin >> str1;
        cin >> str2;
        guess(str1, str2);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值