当前位置:网站首页>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 );
}
}边栏推荐
- vs code保存时 出现两次格式化
- Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
- Audio and video engineer YUV and RGB detailed explanation
- Social networking website for college students based on computer graduation design PHP
- RDD conversion operator of spark
- 从顶会论文看2022年推荐系统序列建模的趋势
- 技术管理进阶——什么是管理者之体力、脑力、心力
- Have a look at this generation
- Sword finger offer 38 Arrangement of strings
- Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
猜你喜欢

从顶会论文看2022年推荐系统序列建模的趋势

Use image components to slide through photo albums and mobile phone photo album pages
![[depth first search notes] Abstract DFS](/img/d4/0cfb5254b0c0d04b4400b4628637d5.jpg)
[depth first search notes] Abstract DFS
![[robot library] awesome robots Libraries](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[robot library] awesome robots Libraries

Computer graduation design PHP part-time recruitment management system for College Students

Paper notes: graph neural network gat
![[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)

【社区人物志】专访马龙伟:轮子不好用,那就自己造!

Extracting key information from TrueType font files

02. Go language development environment configuration
随机推荐
Paper notes: graph neural network gat
Computer graduation design PHP animation information website
RDD partition rules of spark
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
剑指 Offer 29. 顺时针打印矩阵
Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
【coppeliasim】6自由度路径规划
Black high-end responsive website dream weaving template (adaptive mobile terminal)
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
更改对象属性的方法
Use the list component to realize the drop-down list and address list
Computer graduation design PHP college student human resources job recruitment network
Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share
I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
Compact lidar global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
模板_快速排序_双指针
ftp上传文件时出现 550 Permission denied,不是用户权限问题
A basic lintcode MySQL database problem
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
2022 edition illustrated network pdf