1

root 站长 2023-08-03 18:57:21 0
#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);
			}
		}
	}
	
	//build_tree 树
	lenb = b.size();
	dfs(1);
	
	for (int i = 1; i <= len; i ++ )
		cout << t[i] << endl;
    return 0;
}
{{ vote && vote.total.up }}

共 12 条回复

root 站长

Kinghero King of the summit

哪道题!!!!!!!!!!