竞赛讨论区 > 我想问一下大佬们第二题的问题
头像
孤琴悲胡
发布于 2021-03-21 16:26
+ 关注

我想问一下大佬们第二题的问题

希望大佬们提供提供测试的数据,我知道我错了但我不知道错在哪,思路感觉是对的谢谢大佬,我就想要要测试案例,题上给的能跑通
#include <iostream>
#include<algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#define  ll long long 
using namespace std;
class Person
{
public:
    int m;
    string name;
    Person(string name,int m)
    {
        this->name = name;
        this->m = m;
    }
    bool operator== (const Person& p1)
    {
        return this->name == p1.name  ;
            
    }
};
stack<ll> s;
string temp;
stack<string> st;
string t;
vector<Person> ve;
void Print()
{
    while (!st.empty())
    {
        t = st.top();
        st.pop();
        if (t[0] >= '0' && t[0] <= '9')
        {
            s.push(t[0] - '0' - 20);
        }
        else if (t == "(")
        {
            int m = 0;
            while (s.top() != -1)
            {
                m += s.top();
                s.pop();
            }
            s.pop();

            if (s.top() >= -20 && s.top() <= -10)
            {
                m = abs(s.top() + 20) * m;
                s.pop();
            }
            s.push(m);
        }
        else if (t == ")")
        {
            s.push(-1);
        }
        else
        {
            auto it = find(ve.begin(), ve.end(), Person(t, 1));
            ll r = it->m;
            if (s.empty())
            {
                s.push(r);
            }
            else if (s.top() >= -20 && s.top() <= -10)
            {
                r = abs(s.top() + 20) * r;
                s.pop();
                s.push(r);
            }
            else
            {
                s.push(r);
            }
        }
    }
    ll m = 0;
    while (!s.empty())
    {
        m += s.top();
        s.pop();
    }
    cout << m << endl;
}
int main()
{
    int m, n;
    cin >> m >> n;
    string name;
    ll kg;
    
    for (int i = 0; i < m; i++)
    {
        cin >> name >> kg;
        ve.push_back(Person(name, kg));
    }
    
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        t.clear();
        for (int j = 0; j < temp.length(); j++)
        {
            if (temp[j] >= 97 && temp[j] <= 122)
            {
                t = st.top();
                st.pop();
            }
            t += temp[j];
            st.push(t);
            t.clear();
        }
        Print();
        //cout << s.size() << " " << st.size() << endl;
    }
}

全部评论

(1) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐