当前位置:网站首页>HDU_ p1237_ Simple calculator_ stack
HDU_ p1237_ Simple calculator_ stack
2022-07-06 02:21:00 【This question AC sleep again】
HDU_p1237_ Simple calculator _stack
Problem Description
Read in one containing only +, -, *, / The non negative integer evaluation expression of , Calculate the value of the expression .
Input
The test input contains several test cases , One line per test case , No more than 200 Characters , Integers and operators are separated by a space . There is no illegal expression . When there is only 0 When the input is over , Do not output the corresponding result .
Output
Output for each test case 1 That's ok , That is, the value of the expression , Accurate to the decimal point 2 position .
Sample Input
1 + 2 4 + 2 * 5 - 7 / 11 0
Sample Output
3.00 13.36
Source
Zhejiang University Computer postgraduate reexamination computer examination -2006 year
//
// #include<bits/stdc++.h>
#include<iostream>
#include<stack>
using namespace std;
int main()
{
char ch;
double ans,x;
while( cin>>x )
{
ch=getchar();
if( !x && ch=='\n' ) break;
ans=0;
stack<double> sk;
sk.push( x );
while( cin>>ch>>x )
{
switch( ch )
{
case '+': sk.push(x); break;
case '-': sk.push(-x); break;
case '*': sk.top()*=x; break;
case '/': sk.top()/=x; break;
}
if( getchar()=='\n' ) break;
}
while( !sk.empty() ) { ans+=sk.top(); sk.pop(); }
printf("%.2lf\n",ans );
}
}
边栏推荐
- GBase 8c数据库升级报错
- 729. My schedule I / offer II 106 Bipartite graph
- 2022年版图解网络PDF
- Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
- Method of changing object properties
- Redis如何实现多可用区?
- Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share
- How to use C to copy files on UNIX- How can I copy a file on Unix using C?
- [community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!
- Computer graduation design PHP part-time recruitment management system for College Students
猜你喜欢
2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
使用npm发布自己开发的工具包笔记
Extracting key information from TrueType font files
Computer graduation design PHP part-time recruitment management system for College Students
PHP campus movie website system for computer graduation design
好用的 JS 脚本
Multi function event recorder of the 5th National Games of the Blue Bridge Cup
PHP campus financial management system for computer graduation design
Redis list
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
随机推荐
【coppeliasim】高效传送带
500 lines of code to understand the principle of mecached cache client driver
genius-storage使用文档,一个浏览器缓存工具
Grabbing and sorting out external articles -- status bar [4]
PHP campus financial management system for computer graduation design
Bigder:34/100 面试感觉挺好的,没有收到录取
大厂镜像库
【机器人库】 awesome-robotics-libraries
Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
Computer graduation design PHP animation information website
General process of machine learning training and parameter optimization (discussion)
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
sql表名作为参数传递
[coppeliasim] 6-DOF path planning
在线怎么生成富文本
Lecture 4 of Data Engineering Series: sample engineering of data centric AI
更改对象属性的方法
SQL statement
The third level of C language punch in