简单计算器
来源:互联网 发布:淘宝手机助手集分宝 编辑:程序博客网 时间:2024/05/06 20:27
http://acm.hdu.edu.cn/showproblem.php?pid=1237
#include <iostream>#include <cstdio>#include <cstring>#include <stack>using namespace std;int main(){//freopen("test.txt", "r", stdin);char str, c;double a, b;stack <double> num;while (scanf("%lf", &a) != EOF){while (!num.empty())num.pop();c = getchar();if (c == '\n' && a == 0)break;num.push(a);scanf("%c", &c);while (scanf("%lf", &b)){if (c == '*') //优先级高,取数,计算{a = num.top();num.pop();num.push(a * b);}else if (c == '/') //同上{a = num.top();num.pop();num.push(a / b);}else if (c == '+') //优先级低,先存入栈num.push(b);else if (c == '-') //减法变成加上那个数的负num.push(-b);c = getchar();if (c == '\n') //结尾break;scanf("%c", &c);getchar();}double ans = 0.0;while (!num.empty()){ans += num.top();num.pop();}printf("%.2lf\n", ans);}return 0;}
0 0
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 简单计算器
- 无MAC法安装genymotion的解决办法_Invalid reply from server..
- ubuntu service XXX start启动报start: Rejected send message, 1 matche
- SQL语句中不等号(!=,<>)
- Interactive association rules exploration app
- 原生js实现焦点轮播图动态切换
- 简单计算器
- 'sudo'不是内部或外部命令,也不是可运行的程序或批处理文件
- notepad 列模式
- 元字符与正则表达式
- 苹果电脑系统重装 —— U盘操作
- CoreData浅谈
- NYOJ 21 三个水杯 (BFS)
- 用window.print()打印指定div里面的内容
- log4j配置详解