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

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

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

2019-11-10 18:14:26
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 房产| 天镇县| 秦皇岛市| 陆川县| 中牟县| 静宁县| 合阳县| 密云县| 丰台区| 淳化县| 开封市| 冕宁县| 北宁市| 图木舒克市| 怀安县| 弥渡县| 巴彦县| 洛川县| 张掖市| 阿鲁科尔沁旗| 含山县| 定日县| 平陆县| 湖口县| 玉山县| 濮阳市| 隆尧县| 正宁县| 惠东县| 阜宁县| 宁蒗| 蒙山县| 武义县| 麻阳| 漯河市| 札达县| 中西区| 孙吴县| 山阳县| 荔波县| 儋州市|