当前位置:网站首页>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 );
}
}边栏推荐
- Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
- Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
- Executing two identical SQL statements in the same sqlsession will result in different total numbers
- Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
- Adapter-a technology of adaptive pre training continuous learning
- 有没有sqlcdc监控多张表 再关联后 sink到另外一张表的案例啊?全部在 mysql中操作
- Redis daemon cannot stop the solution
- MySQL learning notes - subquery exercise
- [Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
- ftp上传文件时出现 550 Permission denied,不是用户权限问题
猜你喜欢
![[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)](/img/ec/7fcdcbd9c92924e765d420f7c71836.jpg)
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)

Ue4- how to make a simple TPS role (II) - realize the basic movement of the role

Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization
![[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!](/img/aa/af98b588efd61d71b1b02609817c49.png)
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!

爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架

Concept of storage engine

The third level of C language punch in

Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
![[robot library] awesome robots Libraries](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[robot library] awesome robots Libraries

【无标题】数据库中一条查询SQL执行的过程
随机推荐
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
使用npm发布自己开发的工具包笔记
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
Sword finger offer 12 Path in matrix
Regular expressions: examples (1)
Leetcode3, implémenter strstr ()
leetcode3、實現 strStr()
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
[coppeliasim] efficient conveyor belt
[depth first search notes] Abstract DFS
大厂镜像库
Redis如何实现多可用区?
Use the list component to realize the drop-down list and address list
SQL statement
怎么检查GBase 8c数据库中的锁信息?
零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO
Using SA token to solve websocket handshake authentication
Executing two identical SQL statements in the same sqlsession will result in different total numbers
更改对象属性的方法