Hack
查看原帖
Hack
340719
EndlessMasterYee楼主2021/1/26 04:26

AC Code:

#include<iostream>
#include<vector>
#include<string>
#include<stack>
using namespace std;

int T;

int main()
{
    cin >> T;
    while (T--)
    {
        int cnt = 0;
        cin >> cnt;
        string test;
        cin >> test;
        test = test.substr(2, test.length() - 3);
        int test_num = 0;
        if (test == "1")
        {
            test_num = 0;
        }
        else
        {
            test = test.substr(2);
            test_num = atoi(test.c_str());
        }
        int cnt_F = 0, cnt_E = 0, now = 0, flag = 0, old_now = 0;
        vector<bool> v(27);
        stack<char> st;
        stack<int> ans;
        bool lock = false;
        while (cnt--)
        {
            char tmp = 0;
            cin >> tmp;
            if (tmp == 'F')
            {
                ++cnt_F;
                cin >> tmp;
                st.push(tmp);
                if (v[tmp - 96])
                {
                    flag = 1;
                }
                v[tmp - 96] = true;
                string a, b;
                cin >> a >> b;
                if (lock)
                {
                    ans.push(0);
                    continue;
                }
                if (isdigit(a[0]))
                {
                    if (isdigit(b[0]))
                    {
                        if (atoi(a.c_str()) <= atoi(b.c_str()))
                        {
                            ans.push(0);
                        }
                        else
                        {
                            ans.push(0);
                            lock = true;
                        }
                    }
                    else
                    {
                        if (!lock)
                        {
                            now += 1;
                            ans.push(1);
                        }
                    }
                }
                else
                {
                    if (isdigit(b[0]))
                    {
                        ans.push(0);
                        lock = true;
                    }
                    else
                    {
                        ans.push(0);
                    }
                }
            }
            else if (tmp == 'E' && cnt_F > cnt_E)
            {
                ++cnt_E;
                if (!st.empty())
                {
                    v[st.top() - 96] = false;
                    st.pop();
                }
                else
                {
                    flag = 1;
                }
                old_now = max(old_now, now);
                if (!ans.empty())
                {
                    now -= ans.top();
                    ans.pop();
                }
                else
                {
                    flag = 1;
                }
                if (cnt_F == cnt_E)
                {// Wrong!
                    lock = false;
                }
            }
            else
            {
                flag = 1;
            }
        }
        if (cnt_F != cnt_E)
        {
            flag = 1;
        }
        if (flag != 1 && old_now == test_num)
        {
            flag = 2;
        }

        if (flag == 1)
        {
            cout << "ERR\n";
        }
        else if (flag == 2)
        {
            cout << "Yes\n";
        }
        else if (flag == 0)
        {
            cout << "No\n";
        }
    }
    return 0;
}

Hack数据:

1
8 O(n^3)
F a 1 n
F b 2 1
E
F b 1 n
F c 1 n
E
E
E

期望输出:

Yes

实际输出:

No

出错的地方在代码中已经注释了。

2021/1/26 04:26
加载中...