求助一下,一道一本通OJ的题
  • 板块灌水区
  • 楼主2021hych
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/1/25 18:13
  • 上次更新2023/10/28 10:59:02
查看原帖
求助一下,一道一本通OJ的题
502707
2021hych楼主2022/1/25 18:13

题目链接:me
我的WAWA代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
stack<int>q;
int x;
string s;
signed main() {
	getline(cin,s);
	for(int i=0;i<s.size()-1;i++) {
		char ch=s[i];
		if(ch!=' ') {
			if(isdigit(ch)) {
				int x=0;
				while(s[i]!=' ') {
					x=x*10+s[i]-'0';
					i++;
				}
				q.push(x);
			}
			else {
				int top1=q.top();
				q.pop();
				int top2=q.top();
				q.pop();
				if(ch=='+') q.push(top2+top1);
				else if(ch=='-') q.push(top2-top1);
				else if(ch=='*') q.push(top2*top1);
				else q.push(top2/top1);
			}
		}
	}
	cout<<q.top();
	return 0;
}

哪位大佬帮个忙,我一直错。

2022/1/25 18:13
加载中...