当前位置:网站首页>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 (IV) - transactions
- 构建库函数的雏形——参照野火的手册
- Computer graduation design PHP enterprise staff training management system
- Regular expressions: examples (1)
- MySQL learning notes - subquery exercise
- 2022 edition illustrated network pdf
- 数据工程系列精讲(第四讲): Data-centric AI 之样本工程
- Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
- Extracting key information from TrueType font files
- Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
猜你喜欢

How to generate rich text online

02. Go language development environment configuration

A basic lintcode MySQL database problem

【clickhouse】ClickHouse Practice in EOI

SQL statement

2022 edition illustrated network pdf

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

Multi function event recorder of the 5th National Games of the Blue Bridge Cup

LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5

在线怎么生成富文本
随机推荐
Virtual machine network, networking settings, interconnection with host computer, network configuration
【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)
VIM usage guide
Using SA token to solve websocket handshake authentication
Campus second-hand transaction based on wechat applet
leetcode3、實現 strStr()
Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
SSM assembly
Spark accumulator
Xshell 7 Student Edition
机器学习训练与参数优化的一般过程 (讨论)
模板_求排列逆序对_基于归并排序
Audio and video engineer YUV and RGB detailed explanation
【无标题】数据库中一条查询SQL执行的过程
Bigder:34/100 面试感觉挺好的,没有收到录取
How to set an alias inside a bash shell script so that is it visible from the outside?
Global and Chinese market of commercial cheese crushers 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL learning notes - subquery exercise
GBase 8c数据库升级报错
Computer graduation design PHP college student human resources job recruitment network