当前位置:网站首页>HDU_p1237_简单计算器_stack
HDU_p1237_简单计算器_stack
2022-07-06 02:06:00 【这题AC再睡.】
Problem Description
读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值。
Input
测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔。没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出。
Output
对每个测试用例输出1行,即该表达式的值,精确到小数点后2位。
Sample Input
1 + 2 4 + 2 * 5 - 7 / 11 0
Sample Output
3.00 13.36
Source
//
// #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 );
}
}边栏推荐
- Jisuanke - t2063_ Missile interception
- 【coppeliasim】6自由度路径规划
- Computer graduation design PHP campus restaurant online ordering system
- [solution] add multiple directories in different parts of the same word document
- Paper notes: graph neural network gat
- Redis key operation
- A basic lintcode MySQL database problem
- 2022 PMP project management examination agile knowledge points (8)
- Social networking website for college students based on computer graduation design PHP
- Gbase 8C database upgrade error
猜你喜欢

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

How does redis implement multiple zones?

How to generate rich text online

论文笔记: 图神经网络 GAT
![[depth first search] Ji Suan Ke: Betsy's trip](/img/b5/f24eb28cf5fa4dcfe9af14e7187a88.jpg)
[depth first search] Ji Suan Ke: Betsy's trip

0211 embedded C language learning

Redis如何实现多可用区?

TrueType字体文件提取关键信息

Paper notes: graph neural network gat

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
随机推荐
【机器人库】 awesome-robotics-libraries
How to generate rich text online
【clickhouse】ClickHouse Practice in EOI
竞价推广流程
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
Use Scrollview and tabhost to realize vertical scrollbars and tabs
RDD conversion operator of spark
MySQL learning notes - subquery exercise
leetcode-2.回文判断
729. My schedule I / offer II 106 Bipartite graph
National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!
Numpy array index slice
TrueType字体文件提取关键信息
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Have a look at this generation
GBase 8c数据库升级报错
How to improve the level of pinduoduo store? Dianyingtong came to tell you
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
01.Go语言介绍
PHP campus movie website system for computer graduation design