+ 1
I need a small advice in codechef long challenge January encoding the string.
I have wrote most of the program but there is a small bug when there is more than 4 nos. i.e. 8 or more ,it encodes the first four nos. correctly but prints the same value for the next 4 nos.I have incremented the value of i after for loop by 4 so that it starts from the next four nos. But in the end I am getting same answer as the previous one. I have been looking at it all day and I wouldn't have asked if there was no other way.pls share some advice.
6 Antworten
0
Will need to see your code
0
I solved it but there is still a small bug
0
Ok but can't help without code
0
for(int y=0;y<z;y++)
{
int p=0,j=4, l=8,mid=8;
for(int i=p;i<j;i++)
{
if(mid==1)
mid=1;
else
mid=mid/2;
if(a[i]=='0')
l=l-mid; //8-4,4-2,2-1
else
l=l+mid;
}
if(l>=1)
l--;
cout<<ar[l];
p=p+4;
j=j+4;
}
cout<<"\n";
}
0
The bug is happening here
0
The value of p and j is not getting incremented