0分,样例已过,玄关!!!
查看原帖
0分,样例已过,玄关!!!
1327102
tysy_020楼主2025/6/21 15:38
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	char m;
	cin >> n;
	stack<char> s;
	stack<long long> a;
	stack<long long> as;
	a.push(n);
	while(cin >> m >> n)
	{
		if(m=='*')
		{
			long long q=a.top()*n;
			a.pop();
			a.push(q);
		}
		else if(m=='/')
		{
			long long q=a.top()/n;
			a.pop();
			a.push(q);
		}
		else
		{
			s.push(m);
			a.push(n);
		}
	}
	while(!a.empty())
	{
		as.push(a.top());
		a.pop();
	}
	long long q=as.top();
	as.pop();
	while(!as.empty())
	{
		if(s.top()=='+')
			q=q+as.top();
		else
			q=q-as.top();
		as.pop();
		s.pop();
	}
	cout << q;
    return 0;
}
2025/6/21 15:38
加载中...