/*
普通有序树转换为二叉树的实验范例
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<sstream>
using namespace std;
int i,hight1,hight2;
string s;
void work(int level1,int level2)
{
int tempson=0; //当前节点儿子数。
while(s[i]=='d'){
i++;tempson++;
work(level1+1,level2+tempson);
}
hight1=hight1>level1?hight1:level1;
hight2=hight2>level2?hight2:level2;
i++;
}
int main()
{
int casei=1;
while(cin>>s,s!="#"){
i=hight1=hight2=0;
work(0,0);
cout<<"Tree "<<casei++<<": "<<hight1<<" => "<<hight2<<endl;
}
return 0;
}
POJ 3437 普通有序树转换为二叉树
最新推荐文章于 2024-09-05 16:03:39 发布