TLE on #5 求调
查看原帖
TLE on #5 求调
1015482
huzixiao楼主2025/2/4 11:49
#include<iostream>
#include<map>
using namespace std;
int n;
char tree[30];
map<char, int> Index;
void front(int node) {
	if (tree[node] == '*') {
		return;
	}
	cout << tree[node];
	front(node * 2);
	front(node * 2 + 1);
}
int main() {
	cin >> n;
	char node, LeftChild, RightChild;
	cin >> node >> LeftChild >> RightChild;
	tree[1] = node;
	Index[node] = 1;
	tree[2] = LeftChild;
	tree[3] = RightChild;
	Index[LeftChild] = 2;
	Index[RightChild] = 3;
	for (int i = 2; i <= n; i++) {
		cin >> node >> LeftChild >> RightChild;
		tree[Index[node] * 2] = LeftChild;
		tree[Index[node] * 2 + 1] = RightChild;
		Index[LeftChild] = Index[node] * 2;
		Index[RightChild] = Index[node] * 2 + 1;
	}
	front(1);
	return 0;
}

2025/2/4 11:49
加载中...