当前位置:网站首页>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 );
}
}边栏推荐
- Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
- Audio and video engineer YUV and RGB detailed explanation
- SPI communication protocol
- How to use C to copy files on UNIX- How can I copy a file on Unix using C?
- selenium 等待方式
- Campus second-hand transaction based on wechat applet
- Xshell 7 Student Edition
- Reasonable and sensible
- This time, thoroughly understand the deep copy
- Computer graduation design PHP campus restaurant online ordering system
猜你喜欢
![[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)](/img/ec/7fcdcbd9c92924e765d420f7c71836.jpg)
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)

Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle

2022 edition illustrated network pdf

同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
![[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice](/img/3a/63f3e89ddf84f23f950ed9620b4405.jpg)
[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice

【clickhouse】ClickHouse Practice in EOI

【机器人库】 awesome-robotics-libraries

Formatting occurs twice when vs code is saved

Virtual machine network, networking settings, interconnection with host computer, network configuration

02.Go语言开发环境配置
随机推荐
Have a look at this generation
Redis key operation
A basic lintcode MySQL database problem
【coppeliasim】6自由度路径规划
Bidding promotion process
【clickhouse】ClickHouse Practice in EOI
Method of changing object properties
genius-storage使用文档,一个浏览器缓存工具
General process of machine learning training and parameter optimization (discussion)
Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
Using SA token to solve websocket handshake authentication
Redis如何实现多可用区?
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
Lecture 4 of Data Engineering Series: sample engineering of data centric AI
Shutter doctor: Xcode installation is incomplete
2022 edition illustrated network pdf
论文笔记: 图神经网络 GAT
Unity learning notes -- 2D one-way platform production method
selenium 等待方式