#include using namespace std; /* 中缀的逻辑表达式 转 后缀的逻辑表达式 测试用例: 0&(0|1|0) 答案: 001|0|& */ unordered_map h{{'|', 1}, {'&', 2}}; string s; string t; stack stk; int main() { cin >> s; for (int i = 0; i < s.size(); i++) { if (isdigit(s[i]) || isalpha(s[i])) t.push_back(s[i]); else if (s[i] == '(') stk.push(s[i]); else if (s[i] == ')') { while (stk.top() != '(') { t.push_back(stk.top()); stk.pop(); } stk.pop(); } else { while (stk.size() && h[s[i]] <= h[stk.top()]) { t.push_back(stk.top()); stk.pop(); } stk.push(s[i]); } } while (stk.size()) { t.push_back(stk.top()); stk.pop(); } printf("%s", t.c_str()); return 0; }