当前位置:网站首页>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;
}
边栏推荐
- What is memoization and what is it good for?
- 为什么我们需要回调
- What is Adobe?
- Interpretation of ML: A case of global interpretation/local interpretation of EBC model interpretability based on titanic titanic rescued binary prediction data set using interpret
- 亿流量大考(2):开发一套高容错分布式系统
- 云计算国内外发展现状
- 易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
- override学习(父类和子类)
- 创建函数报错,提示DECLARE定义语法问题
- 什么是memoization,它有什么用?
猜你喜欢

ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例

113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself

FinClip,助长智能电视更多想象空间

MiniAPI of .NET6 (14): Cross-domain CORS (Part 1)

Summary bug 】 【 Elipse garbled solution project code in Chinese!

Cloud platform construction solutions

Quickly build a website with static files

LabVIEW code generation error 61056

113. 授人以渔 - 如何自行查询任意 SAP UI5 控件属性的文档和技术实现细节

.NET6之MiniAPI(十四):跨域CORS(上)
随机推荐
golang写的存储引擎,基于b+树,mmap
How many way of calling a function?
Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素科研试剂
PowerMockup 4.3.4::::Crack
网络基础学习系列四(网络层,数据链路层和一些其他重要协议或技术)
目标检测技术研究现状及发展趋势
Canvas App中点击图标生成PDF并保存到Dataverse中
RPA power business automation super order!
start with connect by implements recursive query
UVa 437 - The Tower of Babylon(白书)
关于IDO预售系统开发技术讲解丨浅谈IDO预售合约系统开发原理分析
Binary search tree to solve the fallen leaves problem
AOSP CameraLatencyHistogram的原理与使用
override learning (parent and child)
Basic Concepts of Graphs
UVa 1025 - A Spy in the Metro (White Book)
UVa 10003 - Cutting Sticks(白书,区间DP)
Work Subtotal QT Packing
软件测试内卷严重,如何提升自己的竞争力呢?
HCIP BGP lab report