Polish calculation
//cww 逆波兰计算器
#include<stack>
#include<cstdio>
#include<iostream>
using namespace std;
stack<double>s;char read(){while (1){printf("Select command and press<Enter>:");char ch; cin>>ch;if (ch=='?'||ch=='='||ch=='+'||ch=='-'||ch=='*'||ch=='/'||ch=='q'||ch=='Q')return ch;puts("Please enter a valid command:");puts("[?]push to stack [=]print top");puts("[+] [-] [*] [/] you know them");puts("[Q]uit =======Bazinga!=======");}
}bool solve(char ch){double x,y;if (ch=='q'||ch=='Q'){puts("Calculation finshed.");return 0;}if (ch=='?'){printf("Enter a real number:");cin>>x; s.push(x);}if (ch=='='){if (s.empty())puts("Stack empty");else printf("%.0lf\n",s.top());}if (ch=='+'||ch=='-'||ch=='*'||ch=='/'){if (s.empty())puts("Stack empty");else{x=s.top(); s.pop();if (s.empty()){puts("Stack has just one entry");s.push(x);}else{y=s.top();s.pop();switch (ch){case'+':s.push(x+y);break;case'-':s.push(x-y);break;case'*':s.push(x*y);break;case'/':s.push(x/y);break;}}}}return 1;
}
//==========cww=2016,2,28=23:27===============
int main(){puts("welcome");while (!s.empty())s.pop();while (solve(read())){}return 0;
}
Polish calculation相关推荐
- leetcode - 150. Evaluate Reverse Polish Notation
前言:记录一下leetcode上的一道题目: 题目网址:https://leetcode.com/problems/evaluate-reverse-polish-notation/descripti ...
- flaash-ACC_LSMOOTH2: Cannot continue with smoothing calculation
2009年6月21日 15:22:22 采用flaash对MOD02HKM数据进行大气校正,在运行中总是出现ACC_LSMOOTH2: Cannot continue with smoothing c ...
- leetcode day1 -- Reverse Words in a String Evaluate Reverse Polish Notation Max Points on a Li
以前从来没做过什么oj,发现做oj和在本地写代码或者纸上写差别还是很大的,觉得今天开始刷oj,特此记录一下. 1.Reverse Words in a String Given an input st ...
- Algorithm:C++语言实现之链表相关算法(单链公共结点问题、一般LCA、括号匹配、最长括号匹配、逆波兰表达式Reverse Polish Notation、直方图矩形面积、收集雨水问题)
Algorithm:C++语言实现之链表相关算法(单链公共结点问题.一般LCA.括号匹配.最长括号匹配.逆波兰表达式Reverse Polish Notation.直方图矩形面积.收集雨水问题) 目录 ...
- nextpolish安装_「三代组装」使用Pilon对基因组进行polish
软件安装 官方提供了编译好的jar包,方便使用 wget https://github.com/broadinstitute/pilon/releases/download/v1.23/pilon-1 ...
- Reverse Polish Notation
http://www.1point3acres.com/bbs/thread-31595-1-1.html 定义一种叫做"Reverse Polish Notation"的表达式: ...
- 21.等值线图(Counter Plot)、Contour Demo、Creating a “meshgrid”、Calculation of the Values、等
21.等值线图(Counter Plot) 21.1.Contour Demo 21.2.Creating a "meshgrid" 21.3.Calculation of the ...
- understanding shader mat4 * vec4 calculation
为什么80%的码农都做不了架构师?>>> this blog from: http://stackoverflow.com/questions/13745334/underst ...
- SAP Analytics Cloud里基于dimension的calculation
基于图表创建动态的calculation: calculation类型为Aggregation,操作为计算dimension出现的个数:count dimension 要获取更多Jerry的原创文章, ...
- LeetCode-150-Evaluate Reverse Polish Notation
算法描述: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are ...
最新文章
- mysql数据字典生成,在线生成mysql数据字典
- 聊聊并发(三)——JAVA线程池的分析和使用
- 自动打包+ios+android,使用 python 自动打包 Android 和 iOS
- tensorflow随笔-collection收集器
- postman模拟post请求的四种请求体
- 《关于我的那些面经》——百度后端(附答案)
- 正则表达式在NLP的基本应用
- mysql中文占两位_mysql 保留两位小数
- web前端优化--图片优化
- 开源中文分词FudanNLP
- 安卓zip解压软件_破解软件之“安卓压缩包zip或rar密码破解(116位数任意破)”...
- CMOS图像传感器OV7725数据手册
- 小程序跳转页面弹出公众号引导用户关注
- 如何使用 R 从 Internet 下载文件
- 2020CSP初赛试题答案解析
- 运维-系统监控方案:基于Grafana的TDengine零依赖监控解决方案
- JQuery 基础 jq选择器 dom操作
- 大暑节气海报图片|大暑节气海报文案
- 微信图标现在可以换颜色了???
- 快速进行OneHot编码——get_dummies()函数
热门文章
- DCO-OFDM可见光通信matlab
- CImage::Loda 方法加载图片失败,因为vs2013中该方法不支持中文变量
- 微软开源 Python 自动化神器 Playwright
- 2022 年江苏省职业院校技能大赛(中职) 网络搭建与应用赛项公开赛卷
- # C语言使用树设计族谱
- V2X方案之OBU介绍
- 欧美游戏业者都挣多少钱
- 【最新】Blender资产库纹理灯光 预设打光技巧
- idea报错cannot access com.*.*
- powershell_windows命令行杀进程(pskill)/进程任务管理/服务管理/(查看/关闭/停止/移除windows移除mysql服务)