Hello, a newbie here. I’m trying to submit my solution, it gives me a SIGSEGV runtime error, and I’m having a hard time figuring out why, can you help?
code:
#include <iostream>
#include <string>
#nclude <stack>
#include <cassert>
using namespace std;
int main() {
int t, len, i;
string s;
stack<char> op;
cin >> t;
assert(t <= 100);
while (t--) {
cin >> s;
len = s.size();
assert(len <= 400);
for (i = 0; i < len; i++) {
if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '^')
op.push(s[i]);
else if (s[i] == ')'){
cout << op.top();
op.pop();
} else if (isalpha(s[i]))
cout << s[i];
}
cout << "\n";
}
return 0;
}
problem link: http://www.spoj.com/problems/ONP/