当前位置:网站首页>2694:逆波兰表达式
2694:逆波兰表达式
2022-07-21 05:21:00 【来斤山楂】
/*
2694:逆波兰表达式
思路,逆波兰表达式是一个递归定义的问题,首先,一个数就是一个逆波兰表达式,
其次,运算符加上两个逆波兰表达式也是逆波兰表达式,故而利用递归解决
注意,exp()返回值是double,用float会报错
atof定义在#include<cstdlib>中,将字符串转换为浮点数,除此外还有atoi字符串转换为
int,itoa int转换为字符串
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
double exp()
{
char s[20];
cin >> s;
switch(s[0]){
case '+': return exp() + exp();
case '-': return exp() - exp();
case '*': return exp() * exp();
case '/': return exp() / exp();
default: return atof(s);
}
}
int main()
{
printf("%f",exp());
return 0;
}
边栏推荐
- Peoplecode variable
- The database is for the salaries table emp above_ No field create index idx_ emp_ no
- Mysql/sql server connects to the database through JDBC to add, delete, modify and query
- Part 06: pooling Technology
- 235. Nearest common ancestor DFS method of binary search tree
- FlinkCDC
- Newly released yolov5 visual actual combat project (1)
- SQL SELECT statement
- Oracle subquery
- Common auxiliary classes with high concurrency
猜你喜欢
Federated learning: spatiotemporal data mining in federated scenarios
ensp配置DHCP
2. Common modules in ansible
Leakage current, no grounding protection measures... 1296 imported electric kettle have major potential safety hazards
table表格
Part 04: guava retry component
[rviz2] error occurs when importing URDF model: could not load resource XXX, unable to open file XXX, error retrieving file XXX
Part 03: SQL syntax tree parsing
Using disassembly debugging and complement to explain 0x80000000 / -1 shaping output exception inconsistency
Reverse proxy haproxy
随机推荐
kettle入门之文本文件导入数据库
The communication process and principle of peer-to-peer host are very simple
Tcp/ip Foundation
JVM运行原理解析
Connections and differences between three-level dispatching
What information does the process control block (PCB) contain
LAMP架构——mysql的安装部署、mysql集群及主从结构(1)
2.Ansible中常用模塊
Zabbix + Distributed Database tidb Implementation of Distributed Database Monitoring
[infrastructure] [flink] Flink / Flink CDC code to achieve business access
高可用集群Keepalived
solr部署以及ik中文分词案例
使用JasperReports时,报出 ReportExpressionEvaluationData 异常
Solr deployment and IK Chinese word segmentation cases
How are web interface resources saved?
Migrate repo managed code to Gerrit
Complete IP protocol number
LNMP ------php7 installation
PeopleSoft warning, error, message box
Encapsulation des machines virtuelles