Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // * * Bismillahir Rahmanir Rahim * *
- // ************************@Author*******************************
- /* Asik Ifthaker Hamim */
- #include <bits/stdc++.h>
- #include<stdlib.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long int ulli;
- typedef long long int lli;
- typedef unsigned long long ull;
- typedef vector<int> vi;
- typedef vector<ll> vl;
- typedef vector<string> vs;
- typedef pair<ll,ll> pr;
- #define pb push_back
- #define sz(n) n.size()
- #define vs(n) (int)n.size()
- #define pp pop_back
- #define sp(n) setprecision(n)
- #define big 1000000007
- #define ffor(a, b) for (int i = a; i <b; i++)
- #define frev(b, a) for (int i = b; i >= a; i--)
- #define PI (acos(-1.0))
- #define torad(x) ((x)*((2*acos(0))/180.0))
- #define todeg(x) ((x)*(180.0/(2*acos(0))))
- #define fixAngle(x) ((x)>1?1:(x)<-1?-1:(x))
- #define tan(a) tan(a)/(pi/180)
- #define sin(a) sin(a)/(pi/180)
- #define cos(a) cos(a)/(pi/180)
- #define inverse_sin(a) asin(a)/(pi/180)
- #define inverse_cos(a) acos(a)/(pi/180)
- #define inverse_tan(a) atan(a)/(pi/180)
- #define eps 1e-9
- const int dr4[] = {0, 1, 0, -1};
- const int dc4[] = {1, 0, -1, 0};
- const int dr8[] = {0, 1, 1, 1, 0, -1, -1, -1};
- const int dc8[] = {1, 1, 0, -1, -1, -1, 0, 1};
- using namespace std;
- double neg_infinity(-std::numeric_limits<double>::infinity());
- #define ran 1000000
- int precedence(char ch)
- {
- if(ch=='+'||ch=='-')
- return 1;
- if(ch=='*'||ch=='/')
- return 2;
- if(ch=='^')
- return 3;
- return 0;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- string Q="A+(B*C-(D/E^F)*G)*H";
- string p="";
- Q+=')';
- stack<char>st;
- st.push('(');
- for(int i=0;Q[i]!='\0';i++)
- {
- if(Q[i]>='A' && Q[i]<='Z')
- {
- p+=Q[i];
- }
- else if(Q[i]=='(')
- {
- st.push(Q[i]);
- }
- else if(Q[i]==')')
- {
- while(st.top()!='(')
- {
- p+=st.top();
- st.pop();
- }
- st.pop();
- }
- else
- {
- while(!st.empty() && precedence(Q[i])<=precedence(st.top()))
- {
- p+=st.top();
- st.pop();
- }
- st.push(Q[i]);
- }
- }
- while(!st.empty())
- {
- p+=st.top();
- st.pop();
- }
- cout<<p<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement