Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string PostfixToInfix();
- int n,m;
- string PostfixToInfix(int m){
- char c;
- string a="", b="", oper="", out="";
- stack<string> stk;
- for (int j = 0; j < m + 1; j++) {
- c = cin.get();
- switch(c) {
- case ' ':
- stk.push(oper);
- oper = "";
- break;
- case '+' : case '-' : case '*' : case '/' : case '%' :
- if (oper != "") {
- stk.push(oper);
- oper = "";
- }
- b = stk.top();
- stk.pop();
- a = stk.top();
- stk.pop();
- oper = "(" + a + c + b + ")";
- stk.push(oper);
- oper = "";
- break;
- default:
- oper += c;
- }
- }
- out = stk.top();
- stk.pop();
- out = out.substr(1, out.length()-2) + '\n';
- return out;
- }
- int main () {
- ios_base::sync_with_stdio(0);
- cin >> n;
- int tab[n];
- string tab2[n];
- for (int i = 0; i < n; i++) {
- cin >> tab[i];
- m = tab[i];
- tab2[i] = PostfixToInfix(m);
- }
- for (int j = 0; j < n; j++) {
- cout << tab2[j];
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment