当前位置:网站首页>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 );
}
}边栏推荐
- Black high-end responsive website dream weaving template (adaptive mobile terminal)
- Number conclusion LC skimming review - 1
- SPI communication protocol
- 01. Go language introduction
- Jisuanke - t2063_ Missile interception
- SSM 程序集
- [width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
- Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
- 【机器人库】 awesome-robotics-libraries
- Using SA token to solve websocket handshake authentication
猜你喜欢

零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO

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

高数_向量代数_单位向量_向量与坐标轴的夹角

数据工程系列精讲(第四讲): Data-centric AI 之样本工程

Using SA token to solve websocket handshake authentication

Online reservation system of sports venues based on PHP

Structural theme model (I) STM package workflow

Redis如何实现多可用区?

构建库函数的雏形——参照野火的手册

Virtual machine network, networking settings, interconnection with host computer, network configuration
随机推荐
How does redis implement multiple zones?
2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition
Global and Chinese markets of nasal oxygen tubes 2022-2028: Research Report on technology, participants, trends, market size and share
Spark accumulator
2022 edition illustrated network pdf
How to set an alias inside a bash shell script so that is it visible from the outside?
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
2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
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
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
Paper notes: limit multi label learning galaxc (temporarily stored, not finished)
MySQL (IV) - transactions
The third level of C language punch in
机器学习训练与参数优化的一般过程 (讨论)
[coppeliasim] 6-DOF path planning
SQL statement
Gbase 8C database upgrade error
Easy to use js script