当前位置:网站首页>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 );
}
}边栏推荐
- 2022年版图解网络PDF
- 729. 我的日程安排表 I / 剑指 Offer II 106. 二分图
- [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
- Competition question 2022-6-26
- 插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
- Selenium waiting mode
- 同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
- 2022年PMP项目管理考试敏捷知识点(8)
- Flutter Doctor:Xcode 安装不完整
猜你喜欢

Tensorflow customize the whole training process

Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022

Leetcode3. Implement strstr()
![[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!](/img/aa/af98b588efd61d71b1b02609817c49.png)
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!

Computer graduation design PHP college student human resources job recruitment network

NumPy 数组索引 切片
![[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)

Redis如何实现多可用区?

Redis list

Computer graduation design PHP college classroom application management system
随机推荐
PHP campus financial management system for computer graduation design
[solution] add multiple directories in different parts of the same word document
更改对象属性的方法
vs code保存时 出现两次格式化
How does redis implement multiple zones?
Computer graduation design PHP animation information website
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
Using SA token to solve websocket handshake authentication
leetcode3、实现 strStr()
Use Scrollview and tabhost to realize vertical scrollbars and tabs
leetcode3、實現 strStr()
[network attack and defense training exercises]
Redis key operation
How to set an alias inside a bash shell script so that is it visible from the outside?
Redis list
在线怎么生成富文本
Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
Online reservation system of sports venues based on PHP
Thinking about the best practice of dynamics 365 development collaboration
Paper notes: limit multi label learning galaxc (temporarily stored, not finished)