Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
kothariji committed Oct 4, 2020
1 parent f9ad941 commit 9bd5de2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Stack/ONP - Transform the Expression.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <bits/stdc++.h>
#define lli long long int
#define endl "\n"
using namespace std;


int main()
{

int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
stack <string> s1;
for(int i = 0; i<s.length();i++)
{
if(s[i] != ')')
{
string temp(1,s[i]);
s1.push(temp);
}
else
{
string a1 = s1.top();
s1.pop();
string a2 = s1.top();
s1.pop();
string a3 = s1.top();
s1.pop();
s1.pop();
s1.push(a3+a1+a2);
}
}
cout<<s1.top()<<endl;
}

}

0 comments on commit 9bd5de2

Please sign in to comment.