当前位置:网站首页>P1449 后缀表达式
P1449 后缀表达式
2022-08-03 22:51:00 【Recursi】
题目描述
所谓后缀表达式是指这样的一个表达式:式中不再引用括号,运算符号放在两个运算对象之后,所有计算按运算符号出现的顺序,严格地由左而右新进行(不用考虑运算符的优先级)。
如: 3*(5-2)+7 \texttt{3*(5-2)+7} 3*(5-2)+7 对应的后缀表达式为: 3.5.2.-*[email protected] \texttt{3.5.2.-*[email protected]} 3.5.2.-*[email protected]。在该式中,@
为表达式的结束符号。.
为操作数的结束符号。
输入格式
输入一行一个字符串 s s s,表示后缀表达式。
输出格式
输出一个整数,表示表达式的值。
样例 #1
样例输入 #1
3.5.2.-*[email protected]
样例输出 #1
16
提示
数据保证, 1 ≤ ∣ s ∣ ≤ 50 1 \leq |s| \leq 50 1≤∣s∣≤50,答案和计算过程中的每一个值的绝对值不超过 1 0 9 10^9 109。
/* * @Description: To iterate is human, to recurse divine. * @Autor: Recursion * @Date: 2022-08-02 18:17:15 * @LastEditTime: 2022-08-02 18:39:47 */
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
const int N = 1e6;
string s;
int a,b;
int n,m;
stack<int> q;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s;
for(int i = 0;i < s.length();i++){
if(s[i] == '@')
break;
else if(s[i] == '.'){
q.push(a);
a = 0;
b = 0;
}
else if(s[i] >= '0' && s[i] <= '9'){
a = b * 10 + s[i] - '0';
b = a;
}
else{
if(s[i] == '+'){
n = q.top();
q.pop();
m = q.top();
q.pop();
q.push(m + n);
}
if(s[i] == '-'){
n = q.top();
q.pop();
m = q.top();
q.pop();
q.push(m - n);
}
if(s[i] == '*'){
n = q.top();
q.pop();
m = q.top();
q.pop();
q.push(m * n);
}
if(s[i] == '/'){
n = q.top();
q.pop();
m = q.top();
q.pop();
q.push(m / n);
}
}
}
cout << q.top() << endl;
return 0;
}
边栏推荐
- log4j-slf4j-impl cannot be present with log4j-to-slf4j
- AOSP CameraLatencyHistogram的原理与使用
- Why do we need callbacks
- UVa 1025 - A Spy in the Metro(白书)
- BMN: Boundary-Matching Network for Temporal Action Proposal Generation Reading Notes
- Kotlin - 扩展函数和运算符重载
- PowerMockup 4.3.4::::Crack
- RPA power business automation super order!
- UVa 10003 - Cutting Sticks(白书,区间DP)
- 直播预告 | 构建业务智联,快速拥抱财务数字化转型
猜你喜欢
Pytest learn-setup/teardown
[b01lers2020]Life on Mars
V8中的快慢数组(附源码、图文更易理解)
静态文件快速建站
2022-08-03 oracle执行慢SQL-Q17对比
ML's yellowbrick: A case of interpretability (threshold map) for LoR logistic regression model using yellowbrick based on whether Titanic was rescued or not based on the two-class prediction dataset
Republish the lab report
Network basic learning series four (network layer, data link layer and some other important protocols or technologies)
rosbridge-WSL2 && carla-win11
Adobe是什么?
随机推荐
3D 语义分割——2DPASS
ML's yellowbrick: A case of interpretability (threshold map) for LoR logistic regression model using yellowbrick based on whether Titanic was rescued or not based on the two-class prediction dataset
Take an example of a web worker
Internet user account information management regulations come into effect today: must crack down on account trading and gray products
V8中的快慢数组(附源码、图文更易理解)
Embedded Systems: Clocks
UVa 10003 - Cutting Sticks(白书,区间DP)
工作小计 QT打包
走迷宫 BFS
utlis 线程池
如何基于WPF写一款数据库文档管理工具(二)
[N1CTF 2018] eating_cms
代码随想录笔记_动态规划_416分割等和子集
Lift, Splat, Shoot: Encoding Images from Arbitrary Camera Rigs by Implicitly Unprojecting to 3D 论文笔记
utils 定时器
Cisco ike2 IPSec配置
Work Subtotal QT Packing
override learning (parent and child)
complete binary tree problem
HDU 5655 CA Loves Stick