请问为啥为这样

P1305 新二叉树

@[yuanbao2013](/user/871590) ```cpp #include<bits/stdc++.h> using namespace std; struct tree{ char l,r; }a[200]; inline void dfs(char c){ printf("%c",c); if(a[c].l) dfs(a[c].l); if(a[c].r) dfs(a[c].r); } int main(){ //移动了n和root int n; char root; //移动了n和root scanf("%d",&n); for(int i=1;i<=n;i++){ char s[4]; scanf("%s",s); if(i==1) root=s[0]; if(s[1]!='*') a[s[0]].l=s[1]; if(s[2]!='*') a[s[0]].r=s[2]; } dfs(root); } ``` $s$ 的大小改大就行了。 但我也不知道为什么 ( 逃
by Wanderer_01 @ 2023-10-12 17:48:48


@[Wanderer_01](/user/544935) 好像s存的是a,b,c,\0,还要有一个\0的原因 知道了,谢谢
by yuanbao2013 @ 2023-10-12 17:53:19


但 scanf 的读入是不会读入回车的。
by Wanderer_01 @ 2023-10-12 17:55:32


|