当前位置:网站首页>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 );
}
}边栏推荐
- 模板_求排列逆序对_基于归并排序
- SSM assembly
- 通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
- 数据工程系列精讲(第四讲): Data-centric AI 之样本工程
- sql表名作为参数传递
- Sword finger offer 38 Arrangement of strings
- Keyword static
- 爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
- 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
- Have a look at this generation
猜你喜欢

Lecture 4 of Data Engineering Series: sample engineering of data centric AI
![[solution] every time idea starts, it will build project](/img/fc/e68f3e459768abb559f787314c2124.jpg)
[solution] every time idea starts, it will build project

Computer graduation design PHP campus restaurant online ordering system

RDD partition rules of spark

MySQL index

A basic lintcode MySQL database problem

Computer graduation design PHP college classroom application management system

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
![[depth first search] Ji Suan Ke: Betsy's trip](/img/b5/f24eb28cf5fa4dcfe9af14e7187a88.jpg)
[depth first search] Ji Suan Ke: Betsy's trip

3D drawing ()
随机推荐
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
使用npm发布自己开发的工具包笔记
Using SA token to solve websocket handshake authentication
在线怎么生成富文本
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
Social networking website for college students based on computer graduation design PHP
FTP server, ssh server (super brief)
[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
Spark accumulator
Prepare for the autumn face-to-face test questions
2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition
Regular expressions: examples (1)
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
Genius storage uses documents, a browser caching tool
模板_求排列逆序对_基于归并排序
Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
Method of changing object properties
Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
Shutter doctor: Xcode installation is incomplete