SEP14 CHEFLR Problem is available in this link.
To simplify this problem, assume the modulo value is 7, then what is resultant node number for the path rll and rlll. I understand that it should be 0 and 6.
But the successful code(CodeChef: Practical coding for everyone) giving it as 0 and -1. please correct me if i am wrong.
#include <stdio.h>
int main ()
{
char ch=0;
int v=0;
int i =1, t_l =0, t_r=0, tc=0, c=0, ret=0 ,count= 0, s =0;
int mod= 1000000007;
scanf("%d\n", &tc);
while (tc){
--tc;
i =1; c=1; v=1;
ret=0;
s =0;
++count;
while (i)
{
ret = scanf ("%c", &ch);
if(ret != 1){
ch='q';
}
++s;
c=!c;
if ( 0== c){
t_l=0;t_r=2;
}
else{
t_l=1; t_r=1;
}
switch(ch)
{
case 'r':
{
v=(v*2) + t_r;
v = v%mod;
if ( 0 == v)
{
v = mod;
}
}
break;
case 'l':
{
v=(v*2) - t_l;
v = v%mod;
if ( 0 == v)
{
v = mod;
}
}
break;
default:
{
v=v%mod;
printf ("%d\n", v);
i =0;
}
break;
}
}
}
return 0;
}