49分RE求调
查看原帖
49分RE求调
1211668
WMY_楼主2024/6/11 17:53
#include <bits/stdc++.h>
using namespace std;

using LL = int64_t;

string str;
string a="";
stack<int>st;

int main() {
	cin >> str;
	for(int i = 0; str[i] != '@'; ++i) {
		if(str[i] == '.') {
			st.push(stoi(a));
			a.clear();
		}
		else if(isdigit(str[i])) a += str[i];
		else {
			int x = st.top(); st.pop();
			int y = st.top(); st.pop();
			if(str[i] == '-') {
				if(isdigit(str[i + 1])) a += '-';
				else st.push(y - x);
			}
			if(str[i] == '+') st.push(y + x);
			if(str[i] == '*') st.push(y * x);
			if(str[i] == '/') st.push(y / x);
		} 
	}
	cout << st.top() << '\n';
	
	return 0;
}

2024/6/11 17:53
加载中...