当前位置:网站首页>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 );
}
}边栏推荐
- 论文笔记: 极限多标签学习 GalaXC (暂存, 还没学完)
- 通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
- Shutter doctor: Xcode installation is incomplete
- Sword finger offer 12 Path in matrix
- 01.Go语言介绍
- SPI communication protocol
- 02. Go language development environment configuration
- NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
- Unity learning notes -- 2D one-way platform production method
- Multi function event recorder of the 5th National Games of the Blue Bridge Cup
猜你喜欢
![[depth first search notes] Abstract DFS](/img/d4/0cfb5254b0c0d04b4400b4628637d5.jpg)
[depth first search notes] Abstract DFS

How to upgrade kubernetes in place
![[ssrf-01] principle and utilization examples of server-side Request Forgery vulnerability](/img/43/a8f302eb69beff4037aadda808f886.png)
[ssrf-01] principle and utilization examples of server-side Request Forgery vulnerability

在线怎么生成富文本

Formatting occurs twice when vs code is saved

【clickhouse】ClickHouse Practice in EOI

500 lines of code to understand the principle of mecached cache client driver

02. Go language development environment configuration

Using SA token to solve websocket handshake authentication

Open source | Ctrip ticket BDD UI testing framework flybirds
随机推荐
使用npm发布自己开发的工具包笔记
Extracting key information from TrueType font files
Leetcode3. Implement strstr()
leetcode-2. Palindrome judgment
Global and Chinese markets of nasal oxygen tubes 2022-2028: Research Report on technology, participants, trends, market size and share
Genius storage uses documents, a browser caching tool
729. My schedule I / offer II 106 Bipartite graph
Redis key operation
Computer graduation design PHP college classroom application management system
[coppeliasim] 6-DOF path planning
It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment
Selenium waiting mode
PHP campus financial management system for computer graduation design
Using SA token to solve websocket handshake authentication
Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
RDD conversion operator of spark
Adapter-a technology of adaptive pre training continuous learning
[network attack and defense training exercises]
在线怎么生成富文本