how to solve ONP problem?
You can solve any of these kinds of problems with the help of stack data structure. I write the code for this problem so take a look and if you don’t get anything, I will try to help.
#include <iostream>
#include <stack>
using namespace std;
int main() {
int t;cin>>t;
while(t--){
string s;cin>>s;
stack<char> stop;
string res="";
for(int i=0;i<s.length();i++){
if(s[i]=='+' || s[i]=='-' || s[i]=='*' || s[i]=='/' || s[i]=='^'){
stop.push(s[i]);
}
else if(s[i]==')'){
res+=stop.top();
stop.pop();
}else if(s[i]!='('){
res+=s[i];
}
}
cout<<res<<'\n';
}
return 0;
}