当前位置:网站首页>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 );
}
}
边栏推荐
- Selenium element positioning (2)
- RDD conversion operator of spark
- PHP campus financial management system for computer graduation design
- Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
- HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
- General process of machine learning training and parameter optimization (discussion)
- Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
- [width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
- PHP campus movie website system for computer graduation design
- Concept of storage engine
猜你喜欢
Pangolin Library: subgraph
0211 embedded C language learning
论文笔记: 图神经网络 GAT
Initial understanding of pointer variables
从顶会论文看2022年推荐系统序列建模的趋势
Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
Overview of spark RDD
Prepare for the autumn face-to-face test questions
剑指 Offer 30. 包含min函数的栈
构建库函数的雏形——参照野火的手册
随机推荐
Lecture 4 of Data Engineering Series: sample engineering of data centric AI
Xshell 7 Student Edition
Know MySQL database
Bigder:34/100 面试感觉挺好的,没有收到录取
技术管理进阶——什么是管理者之体力、脑力、心力
PAT甲级 1033 To Fill or Not to Fill
Redis key operation
500 lines of code to understand the principle of mecached cache client driver
Unity learning notes -- 2D one-way platform production method
Shutter doctor: Xcode installation is incomplete
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
好用的 JS 脚本
PHP campus movie website system for computer graduation design
How does redis implement multiple zones?
01. Go language introduction
Redis daemon cannot stop the solution
构建库函数的雏形——参照野火的手册
Prepare for the autumn face-to-face test questions
How to generate rich text online