Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com
And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Sunday, January 19, 2014

NICEBTRE-Nice Binary Trees

Nice Binary Trees

below given code is for nicebtre spoj or nice binary trees spoj.
My code looks weird so get my code modified from net. :p

#include <stdio.h>
char s[10001];
int i;
int max(int p,int q)
{
        return p > q ? p : q;
}

int length()
{
        if (s[i++] =='l')
             return 1;
        else
            return max(length(),length())+1;
}
int main()
{
        int t;
        scanf("%d",&t);
        while (t--)
        {
                scanf("%s", s);
                i=0;
                printf("%d\n",length() - 1);
        }
        return 0;
}