中缀转后缀
来源:互联网 发布:播放视频文件修复软件 编辑:程序博客网 时间:2024/06/06 03:57
#include<iostream>#include<stdio.h>#include<cstring>#include<stack>using namespace std;int first(char b){ if(b=='(') return 0; else if(b=='+'||b=='-') return 1; else if(b=='*'||b=='/') return 2;}int main(){ int k; char a[200]; scanf("%d",&k); getchar(); while(k--) { gets(a); stack<char>s; for(int i=0; i<strlen(a); i++) { if(a[i]>='0'&&a[i]<='9') printf("%c ",a[i]); else if(a[i]=='(') s.push(a[i]); else if(a[i]==')') { while(s.top()!='(') { printf("%c ",s.top()); s.pop(); } s.pop(); } else if(a[i]=='+'||a[i]=='-'||a[i]=='*'||a[i]=='/') { if(!s.empty()) { while(!s.empty()&&first(a[i])<=first(s.top())) { printf("%c ",a[i]); s.pop(); } } s.push(a[i]); } } while(!s.empty()) { printf("%c ",s.top()); s.pop(); } printf("\n"); } return 0;}
引用文章地址:
http://cc.siso.edu.cn/ds/16.html
- -
0 0
- 中缀转后缀&后缀求值
- c 中缀转后缀
- 中缀转后缀
- 中缀转后缀表达式
- 中缀转后缀
- 中缀转后缀
- 中缀转后缀求值
- 表达式中缀转后缀
- Nyoj467【中缀转后缀】
- 中缀转后缀
- 中缀转后缀
- 中缀转后缀
- 中缀转后缀
- 中缀转后缀
- 中缀转后缀
- 中缀转后缀
- 中缀转后缀表达式
- 中缀转后缀
- 【VS开发】CListBox智能滚动设置
- [图解教程]Axis2与Eclipse整合开发Web Service之二:WSDL逆向生成服务端
- 关于Java线程学习
- Runtime方法的使用—Object篇
- android自定义控件-瀑布流
- 中缀转后缀
- pyftpdlib and RFC
- Java -- Map遍历及各方法性能分析
- Android 调用百度识图工具
- 小波变换的C++实现
- 互联网思维到底是什么?
- 正则表达式
- html笔记
- php yii框架 post csrf