10分求解
查看原帖
10分求解
767048
Rookie_h楼主2023/2/12 12:17
#include <bits/stdc++.h>
using namespace std;
#define is ==
stack<int> st1;
stack<char> st2;
char linshi[1000002] = {'*'};
int swap()
{
    long long int aim = 0;
    for (long long int i = 0; i < strlen(linshi); i++)
    {
        if (linshi[i] == '*')
            break;
        aim = aim * 10 + (linshi[i] - '0');
        linshi[i] = '*';
    }
    return aim;
}
int main()
{
    string s;
    long long int f = 0, flag, a1, a2;
    cin >> s;
    for (long long int i = 0; i < s.size(); i++)
    {
        if (f is 0)
            flag = 0;
        if (s[i] >= '0' && s[i] <= '9')
        {
            f = 1;
            linshi[flag] = s[i];
            flag++;
        }
        else
        {
            f = 0;
            st1.push(swap());
            if (st2.empty())
            {
                st2.push(s[i]);
            }
            else
            {
                if (st2.top() is '+')
                    st2.push(s[i]);
                else if (st2.top() is '*' && s[i] is '+')
                {
                    a1 = st1.top();
                    st1.pop();
                    a2 = st1.top();
                    st1.pop();
                    st1.push(a1 * a2);
                    st2.pop();
                    st2.push(s[i]);
                }
                else
                    st2.push(s[i]);
            }
        }
        if (i is s.size() - 1)
            st1.push(swap());
    }
    //cout << st2.top();
    //st1.pop();
    //cout << st1.top();
    while (!st2.empty())
    {
        a1 = st1.top();
        st1.pop();
        a2 = st1.top();
        st1.pop();
        if (st2.top() is '+')
        {
            st2.pop();
            st1.push(a1 + a2);
        }
        else
        {
            st2.pop();
            st1.push(a1 * a2);
        }
    }
     cout << st1.top() % 10000;
}

自己用比较简单是数据测试没啥问题 但是网站给的测试数据第二个就不过了 下载下来看了一下感觉是长度的原因但是不知道怎么改

2023/2/12 12:17
加载中...