SDUT 2132 数据结构实验之栈二:一般算术表达式转换成后缀式
来源:互联网 发布:php企业网站模板 编辑:程序博客网 时间:2024/06/06 18:11
数据结构实验之栈二:一般算术表达式转换成后缀式
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
对于一个基于二元运算符的算术表达式,转换为对应的后缀式,并输出之。
输入
输入一个算术表达式,以‘#’字符作为结束标志。
输出
输出该表达式转换所得到的后缀式。
示例输入
a*b+(c-d/e)*f#
示例输出
ab*cde/-f*+
#include <bits/stdc++.h>using namespace std;char s[1010];int Judge(char ch){ switch(ch) { case '+': case '-': return 1; case '*': case '/': return 2; default : return 3; }}int main(){ std::ios::sync_with_stdio(false); char ch; int top = 0; while(cin>>ch && ch != '#') { if(ch >= 'a' && ch <= 'z') { cout<<ch; } else if(ch != ')') { while(top && s[top] != '(' && Judge(s[top]) >= Judge(ch)) { cout<<s[top]; top--; } s[++top] = ch; } else { while(s[top] != '(') { cout<<s[top]; top--; } top--; } } while(top) { cout<<s[top]; top--; } cout<<endl; return 0;}
0 0
- [SDUT](2132)数据结构实验之栈二:一般算术表达式转换成后缀式 ---栈
- SDUT 2132 数据结构实验之栈二:一般算术表达式转换成后缀式
- SDUT 2132 数据结构实验之栈二:一般算术表达式转换成后缀式
- SDUT 2132 数据结构实验之栈二:一般算术表达式转换成后缀式
- 数据结构实验之栈二:一般算术表达式转换成后缀式 SDUT 2132
- SDUT 2132 数据结构实验之栈二:一般算术表达式转换成后缀式
- 数据结构实验之栈二:一般算术表达式转换成后缀式 (sdut oj 2132)
- SDUT 2132 数据结构实验之栈二:一般算术表达式转换成后缀式
- SDUT OJ 数据结构实验之栈二:一般算术表达式转换成后缀式
- 数据结构实验之栈二:一般算术表达式转换成后缀式 SDUT
- sdut oj2132数据结构实验之栈二:一般算术表达式转换成后缀式
- sdut 数据结构实验之栈二:一般算术表达式转换成后缀式
- 数据结构实验之栈与队列二:一般算术表达式转换成后缀式 sdut-oj
- 2132 数据结构实验之栈二:一般算术表达式转换成后缀式
- 数据结构实验之栈二:一般算术表达式转换成后缀式 2132
- 2132 数据结构实验之栈与队列二:一般算术表达式转换成后缀式
- 2132-数据结构实验之栈与队列二:一般算术表达式转换成后缀式
- SDUT2132数据结构实验之栈二:一般算术表达式转换成后缀式(栈)
- leetcode 106 【中序,后序建树】
- C++实现floyd-warshall算法
- 在CSDN的第一篇博客。
- 最长公共子串(Longest Common Substring)
- IntelliJ 14 maven3.3.3 -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME
- SDUT 2132 数据结构实验之栈二:一般算术表达式转换成后缀式
- Linux网络编程必看书籍推荐 网络学习的捷径,正在学习中
- 远程问题解决方案(连接到** 的凭据无法工作,请输入新凭据)
- 【20150525-20150529】sql、oracle方向总结(truncate、execute、exception、系统视图与表属性)
- chapter11test2
- MongoDB数据库更新和删除文档
- C++怎么把整型、浮点型、字符串格式化输出到一个字符串中
- NDK 使用流程
- O2O平台思考之可持续闭环:在这盘热棋中你打算走多远