Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一直wa,求路过的大神给组数据

Posted by 2012082324 at 2013-10-19 22:56:03 on Problem 3437
#include <iostream>
#include <string.h>

using namespace std;

int i;
char str[10010];
int D(int d)
{
    int d1, d2;
    if(str[i]=='u') return 0;
    else
    {
		i++;
        d1 = D(d1);
		i++;
        d2 = D(d2);
        return d1>d2?d1+1:d2+1;
    }

}
int main()
{
    int j, l ,c, d1, d2,count=1;
    while(cin>>str)
    {
        if(strcmp(str, "#")==0)break;
        l =strlen(str);c = d1 = 0;
        for(j=0;j<l;j++)
        {
            if(str[j]=='d') c++;
            else
            {
                if(c>d1) d1 = c;
                c = 0;
            }
        }
        str[j]='u';
		i = 0;
        d2 = D(0);
        cout << "Tree " << count <<": "<<d1<<" => "<<d2<<endl;
        count++;
    }

    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator