国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

數據結構實驗之棧二:一般算術表達式轉換成后綴式

2019-11-10 19:02:11
字體:
來源:轉載
供稿:網友

PRoblem Description 對于一個基于二元運算符的算術表達式,轉換為對應的后綴式,并輸出之。 Input 輸入一個算術表達式,以‘#’字符作為結束標志。 Output

輸出該表達式轉換所得到的后綴式。 Example Input

a*b+(c-d/e)*f#

Example Output

ab*cde/-f*+

Hint

Author

#include <stdio.h>#include<math.h>#include <stack>#include <iostream>#include <algorithm>#include <bits/stdc++.h>using namespace std;int main(){ stack <char> p; char kk; while(kk=getchar()) { if(kk>='a'&&kk<='z'||kk>='A'&&kk<='Z') { printf("%c", kk); } else if(kk=='+'||kk=='-') { while(!p.empty()&&(p.top()=='*'||p.top()=='/')) { printf("%c", p.top()); p.pop(); } p.push(kk); } else if(kk=='*'||kk=='/') { p.push(kk); } else if(kk=='(') { p.push(kk); } else if(kk==')') { while(p.top()!='(') { printf("%c", p.top()); p.pop(); } p.pop(); } else if(kk=='#') { while(!p.empty()) { printf("%c", p.top()); p.pop(); } break; } } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 咸丰县| 无棣县| 萝北县| 安远县| 崇左市| 南昌县| 微山县| 东乡县| 邵东县| 盐山县| 略阳县| 鲜城| 昭觉县| 文成县| 得荣县| 石河子市| 中西区| 都匀市| 革吉县| 贡山| 徐州市| 平湖市| 万山特区| 鹤庆县| 清远市| 东海县| 邯郸市| 庄浪县| 定安县| 闽侯县| 黄石市| 延庆县| 句容市| 临清市| 育儿| 拉萨市| 宝应县| 商南县| 临江市| 麦盖提县| 淳安县|