题意:给出一个深度优先遍历树的up down顺序,求这棵树以及这棵树变为”左子右兄”树的高度
思路:直接dfs,x代表树1的高度,y代表树2的高度
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
int h1=,h2=,u=;
char s[];
int read(){
char ch=getchar();int f=,t=;
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void dfs(int x,int y){
int son=;
while (s[u]=='d'){
u++;son++;
dfs(x+,y+son);
}
u++;
h1=std::max(h1,x);
h2=std::max(h2,y);
}
int main(){
int T=;
scanf("%s",s);
while (s[]!='#'){
h1=h2=u=;
dfs(,);
printf("Tree %d: %d => %d\n",++T,h1,h2);
scanf("%s",s);
}
}