hdoj 简单计算器 1237 (栈模拟)
来源:互联网 发布:淘宝app官方下载 编辑:程序博客网 时间:2024/05/29 13:07
简单计算器
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15924 Accepted Submission(s): 5444
Problem Description
读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值。
Input
测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔。没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出。
Output
对每个测试用例输出1行,即该表达式的值,精确到小数点后2位。
Sample Input
1 + 24 + 2 * 5 - 7 / 110
Sample Output
3.0013.36
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){double a[210];double b,sum;int top,i,j,k;char c;while(scanf("%lf",&b)){c=getchar();//getchar()用来吸收空格和换行 if(b==0&&c=='\n')break;else{top=0;memset(a,0,sizeof(a));a[top++]=b;}while(1){scanf("%c %lf",&c,&b);if(c=='*')a[top-1]*=b;else if(c=='/')a[top-1]/=b;else if(c=='+')a[top++]=b;else if(c=='-')a[top++]=-b;if(getchar()=='\n')break;}sum=0;for(i=0;i<top;i++)sum+=a[i];printf("%.2lf\n",sum);}return 0;}
0 0
- hdoj 简单计算器 1237 (栈模拟)
- hdoj--1237--简单计算器(栈模拟)
- HDOJ 1237 简单计算器(简易栈)
- HDOJ 1237 简单计算器(栈)
- hdoj 1237 简单计算器(计算器应用)
- hdoj 1237 简单计算器(栈)
- hdoj 1237简单计算器 【栈】
- hdoj 1237 简单计算器《栈》
- hdoj 1237 简单计算器
- hdoj 1237 简单计算器
- hdoj 1237 简单计算器
- hdoj 1237 简单计算器
- HDOJ 1237 简单计算器
- HDOJ 1237 简单计算器
- HDOJ 题目1237简单计算器(栈,逆波兰式)
- HDOJ 1237 简单计算器(堆栈)
- HDOJ 1237题 简单计算器
- hdu 1237 简单计算器(数组模拟栈,队列)
- 两年嵌入式软件开发的工作感想
- eclipse-3.3.2在CentOS-5.4下启动时崩溃的解决方法
- ifconfig eth0 XXX 显示NO SUCH DEVICE
- JFinal 常见报错
- PAT乙级题目1002的构思和简单实践
- hdoj 简单计算器 1237 (栈模拟)
- HackerRank Self Balancing Tree(AVL树)
- Mysql lvm备份和恢复
- 项目二—— 大数据集上排序算法性能的体验
- 122Best Time to Buy and Sell Stock II
- Dragon board 410c硬件简述
- 各种基本排序算法总结
- OpenGL编程指南 (红宝书 第八版) 样例代码配置问题汇总
- 谷歌发布2015年度搜索排行榜