poj3437 多叉树转为二叉树

来源:互联网 发布:淘宝刚开的店怎么推广 编辑:程序博客网 时间:2024/05/29 13:10

 

#include<iostream>using namespace std;string s;int i,yuan,hou,len=1;void f(int yu,int ho){ int t=0; while(s[i]=='d'){  t++;  i++;  f(yu+1,ho+t); } yuan=yu>yuan? yu:yuan; hou=ho>hou? ho:hou; i++;}int main(){ while(cin>>s&&s[0]!='#'){  i=yuan=hou=0;  f(0,0);  cout<<"Tree "<<len++<<": "<<yuan<<" => "<<hou<<endl; } return 0;}



0 0
原创粉丝点击