国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 扎囊县| 宁国市| 济宁市| 磴口县| 宜兰市| 永靖县| 永城市| 内丘县| 和平县| 玉林市| 赫章县| 青阳县| 余江县| 茶陵县| 元阳县| 镇康县| 同仁县| 宾阳县| 汾阳市| 南投市| 绥德县| 遂平县| 阿拉善左旗| 麻栗坡县| 师宗县| 沅江市| 图片| 延寿县| 阳东县| 慈利县| 丹棱县| 会东县| 陕西省| 出国| 措美县| 桃园市| 镶黄旗| 招远市| 德庆县| 宝鸡市| 林周县|