// http://www.spoj.com/problems/ONP/
#include <iostream>
#include <string>
#include <cctype>
#include <stack>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::stack;
int main(int argc, char* argv[]) {
int testnum;
cin >> testnum;
while (testnum-- > 0) {
string incmd;
cin >> incmd;
stack<char> oprs;
string::const_iterator it = incmd.begin();
for (; it!=incmd.end(); ++it) {
char c = *it;
if (c=='+' ||
c=='-' ||
c=='*' ||
c=='/' ||
c=='^') {
oprs.push(c);
continue;
}
if (c==')') {
cout << oprs.top();
oprs.pop();
} else {
if (std::isalpha(c)) {
cout << c;
}
}
}
cout << endl;
}
}
Transform the Expression
最新推荐文章于 2022-04-28 14:45:14 发布