本文最后更新于 173 天前,其中的信息可能已经有所发展或是发生改变。
https://www.luogu.com.cn/problem/P1449
//自认为代码清晰,需要注意的地方只有"-"、"/"时y,z的顺序即可
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
typedef long long LL;
typedef list<int>::iterator Iter;
list<int> L;
deque<int> dq;
queue<int> q;
stack<int> s;
vector<int> a(N + 1, 0);
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
char ch;
int x = 0, y = 0, z = 0, ans = 0;
while (ch != '@') {
ch = getchar();
if (ch == '.') {s.push(x);x = 0;}
else if (ch == '*') {y = s.top();s.pop();z = s.top();s.pop();ans = y * z;s.push(ans);}
else if (ch == '/') {y = s.top();s.pop();z = s.top();s.pop();ans = z / y;s.push(ans);}
else if (ch == '+') {y = s.top();s.pop();z = s.top();s.pop();ans = y + z;s.push(ans);}
else if (ch == '-') {y = s.top();s.pop();z = s.top();s.pop();ans = z - y;s.push(ans);}
else x = x * 10 + (ch - '0');
}
cout << s.top();
return 0;
}