#pragma GCC optimize(2,3,"Ofast")
#include<bits/stdc++.h>
using namespace std;
stack<string> a, b;
string t[1010];
int len = 0, lenb;
void dfs(int root)
{
if (root > lenb) return;
dfs(2*root);
t[root] = b.top();
b.pop();
len++;
dfs(2*root+1);
}
signed main()
{
string s;
getline(cin, s); s += ' ';
for (int i = 0, j = 0; s[i]; i ++ )
{
if (s[i] == ' ')
{
string d = s.substr(j, i-j);
j = i + 1;
if (d == "&" || d == "|" || d == "!")
{
if (a.size() >= 2) b.push(a.top()), a.pop();
b.push(d);
b.push(a.top()), a.pop();
}
else
{
a.push(d);
}
}
}
lenb = b.size();
dfs(1);
for (int i = 1; i <= len; i ++ )
cout << t[i] << endl;
return 0;
}
共 12 条回复
哪道题!!!!!!!!!!