【leetcode】Evaluate Reverse Polish Notation
来源:互联网 发布:网络主播公司怎么赚钱 编辑:程序博客网 时间:2024/06/06 03:24
#include<iostream>#include<stack>#include<string>#include<vector>using namespace std;class Solution{public: double fun(vector<string> a) { stack<string>result; for(int i=0;i<a.size();i++) { cout<<a[i]<<endl; if(!a[i].compare("+")||!a[i].compare("-")||!a[i].compare("*")||!a[i].compare("/")) { cout<<"lf"<<endl; string c1=result.top(); result.pop(); string c2=result.top(); result.pop(); int m=stoi(c1); int n=stoi(c2);; int num; if(a[i][0]=='+') num=n+m; else if(a[i][0]=='-') num=n-m; else if(a[i][0]=='*') num=n*m; else num=n/m; result.push(to_string(num)); } else { cout<<"re"<<endl; result.push(a[i]); } } return stod(result.top()); } };void main(){ Solution solution; string arr[5]={"4", "13", "5", "/", "+"}; vector<string>a(arr,arr+5); cout<<solution.fun(a)<<endl;}
0 0
- Evaluate Reverse Polish Notation | leetcode
- leetcode-Evaluate Reverse Polish Notation
- Leetcode: Evaluate Reverse Polish Notation
- LeetCode - Evaluate Reverse Polish Notation
- LeetCode | Evaluate Reverse Polish Notation
- Leetcode: Evaluate Reverse Polish Notation
- Leetcode: Evaluate Reverse Polish Notation
- Evaluate Reverse Polish Notation (LeetCode)
- leetcode: Evaluate Reverse Polish Notation
- Leetcode Evaluate Reverse Polish Notation
- [LeetCode] Evaluate Reverse Polish Notation
- [LeetCode] Evaluate Reverse Polish Notation
- Evaluate Reverse Polish Notation -- LeetCode
- 【LeetCode】Evaluate Reverse Polish Notation
- LeetCode-Evaluate Reverse Polish Notation
- LeetCode:Evaluate Reverse Polish Notation
- LeetCode Evaluate Reverse Polish Notation
- Leetcode:Evaluate Reverse Polish Notation
- 讲解Oracle数据库移植到MySQL
- Android屏幕适配
- 数据结构基础 之 图 的 邻接矩阵实现与邻接表实现
- DirectUI界面编程(一)创建第一个应用
- WordPress 中 body_class 函数那些事
- 【leetcode】Evaluate Reverse Polish Notation
- 内存溢出和内存泄漏的区别
- 工作日志2
- 【j2ee spring】41、巴巴运动网的产品查询
- Climbing the Hill - HDU 4315 阶梯博弈变形
- 支持向量分类机
- 11584 - Partitioning by Palindromes(DP)
- AIX用裸设备扩数据库表空间专题 (前面 + 自己的comments)
- Opencv之Mat::step小记