⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4011320_tle.cc

📁 北大大牛代码 1240道题的原代码 超级权威
💻 CC
字号:
#include <queue>
#include <ctype.h>
#include <algorithm>

using namespace std;

char exp[10011];

struct node
{
	struct node * left, *right, *parent;
	char op;
};

node *root;

void build(node *t, int p)
{
	if (p < 0)
		return ;
	
	if (t->left && t->right)
	{
		build(t->parent, p);
		return ;
	}
	node *tmp = new node();
	tmp->op = exp[p];
	tmp->left = tmp->right = NULL;
	tmp->parent = t;
	if (t->left == NULL)
	{
		t->left = tmp;
		if (isupper(exp[p]))
		{
			build(tmp, p - 1);
		}
		else
		{
			build(t, p - 1);
		}
	}
	else
	{
		t->right = tmp;
		if (isupper(exp[p]))
		{
			build(tmp, p - 1);
		}
		else
		{
			build(t->parent, p - 1);
		}
	}
}

queue <node *> que;

void report(bool error)
{
	while (error)
	{
		puts("I love shengqi");
	}
}

void visit()
{
	node *t;
	int p (0);

	que.push(root);
	while (!que.empty())
	{
		t = que.front();
		exp[p++] = t->op;
		que.pop();
		if (t->left == NULL)
			continue;
		report(t->right == NULL);
		que.push(t->right);
		que.push(t->left);
	}
	exp[p] = '\0';
	reverse(exp, exp + p);
	puts(exp);
}

int main()
{
	int n, l;

	scanf("%d", &n);
	while (n--)
	{
		scanf("%s", exp);
		l = strlen(exp);
		root = new node();
		root->op = exp[--l];
		root->left = root->right = root->parent = NULL;
		build(root, --l);
		visit();
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -