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

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

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

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

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昭通市| 岳阳县| 公安县| 大荔县| 五指山市| 沧州市| 方正县| 新昌县| 孟州市| 临高县| 旬邑县| 循化| 沙坪坝区| 喀什市| 井研县| 孟津县| 潜山县| 卢湾区| 蓝田县| 同江市| 余江县| 扎囊县| 娄烦县| 阳西县| 渭源县| 故城县| 汝南县| 太白县| 武定县| 祁门县| 博客| 禄丰县| 南平市| 盐城市| 玛沁县| 彭泽县| 交城县| 平原县| 自贡市| 江达县| 营山县|