大佬们,我只ac了最后一个,求改
查看原帖
大佬们,我只ac了最后一个,求改
890907
202240210230FUQIANG楼主2024/9/7 23:00

大佬们,我只ac了最后一个,求改

// https://ac.nowcoder.com/discuss/926597
#include <bits/stdc++.h>
using namespace std;
int a = 0, b = 0;

int hanshu1(string str)
{

    int i = 0, hua = 0, dui = 0;
    while (1)
    {
        if (str[i] == 'W')
            hua++;
        else
            dui++;
        if (hua >= 11 || dui >= 11)
        {
            if (hua - dui >= 2)
            {
                cout << hua << ':' << dui << endl;
                dui = 0;
                hua = 0;
                a++;
            }

            if (dui - hua >= 2)
            {
                cout << hua << ':' << dui << endl;
                dui = 0;
                hua = 0;
                b++;
            }
        }
        i++;
        if (str[i] == 'E')
        {
            cout << hua << ':' << dui << endl;
            break;
        }
    }
    return 0;
}
int hanshu2(string str)
{
    int i = 0, hua = 0, dui = 0;
    while (1)
    {
        if (str[i] == 'W')
            hua++;
        else if (str[i] == 'L')
            dui++;
        if (hua >= 21 || dui >= 21)
        {
            if (hua - dui >= 2)
            {
                cout << hua << ':' << dui << endl;
                dui = 0;
                hua = 0;
                a++;
            }

            if (dui - hua >= 2)
            {
                cout << hua << ':' << dui << endl;
                dui = 0;
                hua = 0;
                b++;
            }
        }
        i++;
        if (str[i] == 'E')
        {
            cout << hua << ':' << dui << endl;
            break;
        }
    }
    return 0;
}
int main()
{
    char a;
    string str;
    int i = 0;

    while (1)
    {
        scanf("%c", &a);

        if (a == 'E')
        {
            str = str + 'E';
            break;
        }
        else if (a == '\n')
            ;
        else
        {
            str = str + a;
        }
    }
    // cout << endl;
    // cout << str << endl;
    hanshu1(str);
    cout << endl;
    hanshu2(str);
    // cout << a << ':' << b << endl;
    return 0;
}

2024/9/7 23:00
加载中...