当前位置:网站首页>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 );
}
}
边栏推荐
- 模板_求排列逆序对_基于归并排序
- MySQL index
- There are so many giants, why should we independently develop POS store cashier system?
- 01. Go language introduction
- The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
- 模板_快速排序_双指针
- 729. My schedule I / offer II 106 Bipartite graph
- Shutter doctor: Xcode installation is incomplete
- MySQL lethal serial question 1 -- are you familiar with MySQL transactions?
- [Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
猜你喜欢
Know MySQL database
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
2022 PMP project management examination agile knowledge points (8)
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
Structural theme model (I) STM package workflow
Computer graduation design PHP college student human resources job recruitment network
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
[solution] every time idea starts, it will build project
PHP campus financial management system for computer graduation design
3D drawing ()
随机推荐
ftp上传文件时出现 550 Permission denied,不是用户权限问题
大厂镜像库
02. Go language development environment configuration
GBase 8c数据库升级报错
3D drawing ()
Pangolin Library: subgraph
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
leetcode3、實現 strStr()
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Have a look at this generation
Structural theme model (I) STM package workflow
[coppeliasim] 6-DOF path planning
How to improve the level of pinduoduo store? Dianyingtong came to tell you
Derivation of Biot Savart law in College Physics
Global and Chinese markets of general purpose centrifuges 2022-2028: Research Report on technology, participants, trends, market size and share
技术管理进阶——什么是管理者之体力、脑力、心力
Initial understanding of pointer variables
【机器人手眼标定】eye in hand
零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO
SSM 程序集