不知道输出的问题
查看原帖
不知道输出的问题
591561
Xianzi_楼主2024/8/25 09:59

我的代码的输出不知道为什么有问题

去掉注释时只会输出最后一个字符,加上注释时会出现一堆奇奇怪怪的东西

#include "bits/stdc++.h"
using namespace std;
struct Node{
	int left, right, father;
}node[50];
void preorder(int x){
	if (node[x].father == -1) return ;
	cout << char(node[x].father + 'a');
	//if (node[x].left != -1)
		preorder(node[x].left);
	//if (node[x].right != -1)
		preorder(node[x].right);
}
int n;
char c, lc, rc;
int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> c >> lc >> rc;
		if (lc != '*') node[c - 'a'].left = lc - 'a';
		else node[c - 'a'].left = -1;
		if (rc != '*') node[c - 'a'].right = rc - 'a';
		else node[c - 'a'].right = -1;
		node[c - 'a'].father = c - 'a';
	}
	preorder(c - 'a');
	return 0;
}

感谢各位大佬帮助,谢谢QwQ

2024/8/25 09:59
加载中...