Hi guys,
I am trying the ONP Transform the Expression problem but got stuck with WA having no idea about the triggering test case(s)…
It worked with the given examples. The idea is basically a FIFO vector for operands and then a stack for operators when getting a ‘)’. I guess I do not understand priority requirement since it also mentioned "no expressions like abc ".Could someone help me with some cases that would get the wrong answer? Many thanks!
#include <iostream>
#include <stack>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector <char> temp_l;
stack <char> temp_o;
char input;
int n;
cin>>n;
std::string line;
std::getline(cin, line);
while(n>0) {
std::getline(cin, line);
std::istringstream iss(line);
while ( iss >> input) {
if (input >= 'a' && input <= 'z')
temp_l.push_back(input);
else if ((input >= '*' && input <= '-') || (input == '^'))
temp_o.push(input);
else if (input == ')') {
for (int i = 0; i < temp_l.size(); i++) {
std::cout << temp_l[i];
}
temp_l.clear();
if (!temp_o.empty()) {
std::cout << temp_o.top();
temp_o.pop();
}
}
}
std::cout<<endl;
n--;
}
return 0;
}