当前位置:网站首页>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 );
}
}
边栏推荐
- Selenium waiting mode
- 【机器人手眼标定】eye in hand
- 2 power view
- 竞价推广流程
- 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
- 通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
- genius-storage使用文档,一个浏览器缓存工具
- Extracting key information from TrueType font files
- Derivation of Biot Savart law in College Physics
- [ssrf-01] principle and utilization examples of server-side Request Forgery vulnerability
猜你喜欢
How to improve the level of pinduoduo store? Dianyingtong came to tell you
Use image components to slide through photo albums and mobile phone photo album pages
2 power view
Initialize MySQL database when docker container starts
Concept of storage engine
selenium 等待方式
How to upgrade kubernetes in place
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
Open source | Ctrip ticket BDD UI testing framework flybirds
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
随机推荐
leetcode-2. Palindrome judgment
02. Go language development environment configuration
Regular expressions: examples (1)
【coppeliasim】6自由度路径规划
抓包整理外篇——————状态栏[ 四]
How to improve the level of pinduoduo store? Dianyingtong came to tell you
Paper notes: limit multi label learning galaxc (temporarily stored, not finished)
The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
阿裏測開面試題
Leetcode sum of two numbers
NumPy 数组索引 切片
Ali test open-ended questions
Gbase 8C database upgrade error
leetcode-2.回文判断
SPI communication protocol
Have a look at this generation
Executing two identical SQL statements in the same sqlsession will result in different total numbers
01.Go语言介绍
[robot library] awesome robots Libraries
RDD partition rules of spark