数据点卡的不够死
查看原帖
数据点卡的不够死
224757
Timmy_Zhong楼主2025/8/31 20:06

上了大学偶然翻回以前写过的题,就发现了数据点不够严谨。对于如下10个数据点全部AC的屎山代码:

#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
    string a, b = "";
    while (cin >> a)
    {
        b += a;
    }
    for (auto c : b)
    {
        if (c == 'E')
        {
            break;
        }
        else if (c == 'W')
        {
            n1++;
        }
        else
        {
            n2++;
        }
        if (((n1 == 11 || n2 == 11) && ((n2 - n1 >= 2) || (n2 - n1 <= -2))) || (n1 >= 10 && n2 >= 10 && ((n2 - n1 >= 2) || (n2 - n1 <= -2))))
        {
            cout << n1 << ":" << n2 << endl;
            n1 = n2 = 0;
        }
    }
    cout << n1 << ":" << n2 << endl
         << endl;
    for (auto c : b)
    {
        if (c == 'E')
        {
            break;
        }
        else if (c == 'W')
        {
            n3++;
        }
        else
        {
            n4++;
        }
        if (((n3 == 21 || n4 == 21) && ((n3 - n4 >= 2) || (n3 - n4 <= -2))) || (n3 >= 20 && n4 >= 20 && ((n3 - n4 >= 2) || (n3 - n4 <= -2))))
        {
            cout << n3 << ":" << n4 << endl;
            n3 = n4 = 0;
        }
    }
    cout << n3 << ":" << n4;
    n1 = n2 = n3 = n4 = 0;
}

Line31和Line53两行将无条件的输出存储分数的变量,即使比赛有可能已经结束。

具体来说,对于输入样例

WWWWWWWWWWWWWWWWWWWWW

输出结果将为

11:0
10:0

21:0
0:0

毫无疑问, 000:0 不输出才是符合题目要求的。从而可以反推没有以 21:021:011:011:00:210:210:110:11 作为结尾的数据点。

2025/8/31 20:06
加载中...