逆波兰式
来源:互联网 发布:犀牛软件最新版本 编辑:程序博客网 时间:2024/05/17 01:21
#include<iostream>
#include<stack>
#include<stack>
using namespace std;
int main(void){
stack <int> sta;
char s[50];
int i , num, a, b, c, sum;
stack <int> sta;
char s[50];
int i , num, a, b, c, sum;
cin >> s;
i = 0;
i = 0;
while (s[i] != '\0'){
num = s[i] - '0';
if (num >= 0 && num <= 9){
sta.push(num);
}
if (s[i] == '+'){
a = sta.top();
sta.pop();
b = sta.top();
sta.pop();
c = b + a;
sta.push(c);
}
if (s[i] == '-'){
a = sta.top();
sta.pop();
b = sta.top();
sta.pop();
c = b - a;
sta.push(c);
}
if (s[i] == '*'){
a = sta.top();
sta.pop();
b = sta.top();
sta.pop();
c = b * a;
sta.push(c);
}
num = s[i] - '0';
if (num >= 0 && num <= 9){
sta.push(num);
}
if (s[i] == '+'){
a = sta.top();
sta.pop();
b = sta.top();
sta.pop();
c = b + a;
sta.push(c);
}
if (s[i] == '-'){
a = sta.top();
sta.pop();
b = sta.top();
sta.pop();
c = b - a;
sta.push(c);
}
if (s[i] == '*'){
a = sta.top();
sta.pop();
b = sta.top();
sta.pop();
c = b * a;
sta.push(c);
}
if (s[i] == '/'){
a = sta.top();
sta.pop();
b = sta.top();
sta.pop();
c = b / a;
sta.push(c);
}
i++;
}
a = sta.top();
sta.pop();
b = sta.top();
sta.pop();
c = b / a;
sta.push(c);
}
i++;
}
sum = sta.top();
cout << sum << endl;
cin.get();
system("pause");
return 0;
}
cout << sum << endl;
cin.get();
system("pause");
return 0;
}
阅读全文
0 0
- 波兰式,逆波兰式
- 波兰式和逆波兰式
- 逆波兰式与波兰式
- 波兰式转换为逆波兰式
- 逆波兰式
- 逆波兰式算法
- java 逆波兰式
- 逆波兰式
- 逆波兰式
- 逆波兰式
- 逆波兰式
- 逆波兰式
- 递归~逆波兰式
- 逆波兰式
- 关于逆波兰式
- 逆波兰式
- 逆波兰式Demo
- 逆波兰式计算
- (lintcode)第22题 平面列表
- Java 线程池的异常处理机制
- HTML标签语义化
- jquery实现限制textarea输入字数实例
- 配置Maven,创建和管理Maven工程 —— 以阿里云服务器为例
- 逆波兰式
- 我的csdn粉丝1600个了, mark一下, 感谢大家支持!
- 17.09.05日报
- R语言文件下载:谁来帮我把这个128个音频下载一下
- Android DiskLruCache完全解析,硬盘缓存的最佳方案
- Atitit 人的面相 脸型分类 编码与识别 attilax总结
- Java之CyclicBarrier使用
- Struts2一个简单的登录跳转
- django-基本命令