当前位置:网站首页>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 );
}
}边栏推荐
- RDD conversion operator of spark
- How to generate rich text online
- PHP campus movie website system for computer graduation design
- 2022年版图解网络PDF
- I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
- How does redis implement multiple zones?
- [depth first search notes] Abstract DFS
- Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
- MySQL index
- 安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
猜你喜欢

Concept of storage engine

零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器

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

SQL statement

Computer graduation design PHP enterprise staff training management system
![[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!

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail

Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械

【机器人库】 awesome-robotics-libraries

PHP campus financial management system for computer graduation design
随机推荐
General process of machine learning training and parameter optimization (discussion)
[coppeliasim] efficient conveyor belt
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
Jisuanke - t2063_ Missile interception
通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
Sword finger offer 12 Path in matrix
Computer graduation design PHP campus restaurant online ordering system
Bigder:34/100 面试感觉挺好的,没有收到录取
2022 PMP project management examination agile knowledge points (8)
ftp上传文件时出现 550 Permission denied,不是用户权限问题
更改对象属性的方法
Publish your own toolkit notes using NPM
Using SA token to solve websocket handshake authentication
Gbase 8C database upgrade error
genius-storage使用文档,一个浏览器缓存工具
The third level of C language punch in
sql表名作为参数传递
Regular expressions: examples (1)
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role