为什么自测能过,提交全RE
查看原帖
为什么自测能过,提交全RE
965685
yyrwlj楼主2023/11/10 22:22

code

#include <bits/stdc++.h>
using namespace std;
const int mod = 13331;
stack<int> num;
stack<char> op;
unordered_map<char, int> fu{{'+', 1}, {'-', 1}, {'*', 2}, {'/', 2}, {'^', 3}};
void eval()
{
    int b = num.top();
    num.pop();
    int a = num.top();
    num.pop();
    char c = op.top();
    op.pop();
    int ans;
    if (c == '+')
        ans = a + b;
    else if (c == '-')
        ans = a - b;
    else if (c == '*')
        ans = a * b;
    else if (c == '/')
        ans = a / b;
    else
    {
        ans = 1;
        while (b--)
            ans = (ans * a) % mod;
    }
    num.push((ans % mod + mod) % mod);
}
int clac(string &s,int a)
{
    while (!num.empty())
        num.pop();
    const int len = s.size();
    for (int i=0;i<len;i++)
    {
        if (s[i] == ' ')
            continue;
        if (s[i] == 'a')
            num.push(a);
        else if (isdigit(s[i]))
        {
            int x = 0, j = i;
            while (j < len && isdigit(s[j]))
                x = x * 10 + s[j++] - '0';
            num.push(x);
            i = j - 1;
        }
        else if (s[i] == '(')
            op.push('(');
        else if (s[i] == ')')
        {
            while (op.top() != '(')
                eval();
            op.pop();
        }
        else
        {
            while (!op.empty() && fu[op.top()] >= fu[s[i]])
                eval();
            op.push(s[i]);
        }
    }
    while (!op.empty())
        eval();
    return num.top();
}
bool check(string &a,string &b)
{
    for (int i=0;i<1000;i++)
        if (clac(a, i) != clac(b, i))
            return false;
    return true;
}
int main()
{
    string s;
    getline(cin, s);
    int n;
    cin >> n;
    getchar();
    string ans = "";
    for (int i=0;i<n;i++)
    {
        string t;
        getline(cin, t);
        if (check(s, t))
            ans += char(i + 'A');
    }
    cout << ans;
    return 0;
}
2023/11/10 22:22
加载中...