POJ 3437 Tree Grafting G++
程序员文章站
2022-07-15 10:46:07
...
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//抄博友程序 背一下
int i;
string s;
int jg1,jg2;
void dfs(int len1,int len2)
{
//cout<<len1<<" "<<len2<<endl;
if(i==s.size())//抄博友
{
return;
}
int son=0;
while(s[i]=='d')
{
i++;
son++;
dfs(len1+1,len2+son);
}
i++;
jg1=max(jg1,len1);
jg2=max(jg2,len2);
}
int main()
{
int o=0;
while(1)
{
o++;
cin>>s;
if(s=="#")
{
break;
}
i=0;
jg1=0;
jg2=0;
dfs(0,0);
cout<<"Tree "<<o<<": "<<jg1<<" => "<<jg2<<endl;;
}
return 0;
}