当前位置:网站首页>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 );
}
}边栏推荐
- 500 lines of code to understand the principle of mecached cache client driver
- 论文笔记: 图神经网络 GAT
- 插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
- 机器学习训练与参数优化的一般过程 (讨论)
- 【机器人手眼标定】eye in hand
- Unreal browser plug-in
- [solution] add multiple directories in different parts of the same word document
- 02.Go语言开发环境配置
- Ali test open-ended questions
- selenium 等待方式
猜你喜欢

Computer graduation design PHP campus restaurant online ordering system

leetcode3、實現 strStr()

Redis如何实现多可用区?

Computer graduation design PHP college classroom application management system

【clickhouse】ClickHouse Practice in EOI

SPI communication protocol

Concept of storage engine
![[flask] official tutorial -part2: Blueprint - view, template, static file](/img/bd/a736d45d7154119e75428f227af202.png)
[flask] official tutorial -part2: Blueprint - view, template, static file

PHP campus financial management system for computer graduation design

Adapter-a technology of adaptive pre training continuous learning
随机推荐
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
Sword finger offer 38 Arrangement of strings
Unity learning notes -- 2D one-way platform production method
MySQL learning notes - subquery exercise
Accelerating spark data access with alluxio in kubernetes
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Prepare for the autumn face-to-face test questions
Use image components to slide through photo albums and mobile phone photo album pages
Thinking about the best practice of dynamics 365 development collaboration
Audio and video engineer YUV and RGB detailed explanation
Global and Chinese markets of general purpose centrifuges 2022-2028: Research Report on technology, participants, trends, market size and share
The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
Paper notes: limit multi label learning galaxc (temporarily stored, not finished)
Computer graduation design PHP animation information website
Publish your own toolkit notes using NPM
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
[solution] every time idea starts, it will build project
数据工程系列精讲(第四讲): Data-centric AI 之样本工程
[network attack and defense training exercises]
正则表达式:示例(1)