当前位置:网站首页>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 );
}
}边栏推荐
- 【机器人手眼标定】eye in hand
- FTP server, ssh server (super brief)
- Gbase 8C database upgrade error
- 使用npm发布自己开发的工具包笔记
- Global and Chinese markets of nasal oxygen tubes 2022-2028: Research Report on technology, participants, trends, market size and share
- 更改对象属性的方法
- Virtual machine network, networking settings, interconnection with host computer, network configuration
- UE4 - how to make a simple TPS role (I) - create a basic role
- 500 lines of code to understand the principle of mecached cache client driver
- 2022年版图解网络PDF
猜你喜欢

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail

剑指 Offer 30. 包含min函数的栈

Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail

2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask 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

Lecture 4 of Data Engineering Series: sample engineering of data centric AI

Pangolin Library: subgraph

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

剑指 Offer 29. 顺时针打印矩阵

Multi function event recorder of the 5th National Games of the Blue Bridge Cup
随机推荐
Use the list component to realize the drop-down list and address list
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Selenium element positioning (2)
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!
0211 embedded C language learning
Bidding promotion process
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
Overview of spark RDD
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
[depth first search] Ji Suan Ke: Betsy's trip
Jisuanke - t2063_ Missile interception
Method of changing object properties
The third level of C language punch in
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
PHP campus financial management system for computer graduation design
在线怎么生成富文本
抓包整理外篇——————状态栏[ 四]
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
剑指 Offer 29. 顺时针打印矩阵