CCF 201903-2 二十四点 100分

时间:2022-03-30 21:31:51

讲真的,C++在敲代码流畅度上被python甩几条街没问题吧。偏偏学校机房没python的服务器 - -

int hehe(string str)
{
    deque<string>s;
    string tmp = "s";
    int xixi = 0;
    for (int i = 0; i < str.size(); ++i)
    {
        if (str[i] == 'x')
        {
            xixi = stoi(s.back());
            s.pop_back();
            xixi *= (str[i + 1] - '0');
            s.push_back(to_string(xixi));
            i++;
        }
        else if (str[i] == '/')
        {
            xixi = stoi(s.back());
            s.pop_back();
            xixi /= (str[i + 1] - '0');
            s.push_back(to_string(xixi));
            i++;
        }
        else
        {
            tmp[0] = str[i];
            s.push_back(tmp);
        }
    }
    xixi = stoi(s.front());
    s.pop_front();
    while (!s.empty())
    {
        if (s.front() == "-")
        {
            s.pop_front();
            xixi = xixi- stoi(s.front());
        }
        else if (s.front() == "+")
        {
            s.pop_front();
            xixi = stoi(s.front()) + xixi;
        }
        s.pop_front();
    }
    return xixi;
}
int main()
{
    int n;
    cin >> n;
    string str;
    while (n--)
    {
        cin >> str;
        if (hehe(str) == 24)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;   
    }
    return 0;
}