+ 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.

4th Jan 2021, 6:57 PM
Aman Rana
Aman Rana - avatar
6 Réponses
0
Will need to see your code
5th Jan 2021, 9:51 AM
Nihar Buliya
Nihar Buliya - avatar
0
I solved it but there is still a small bug
5th Jan 2021, 11:10 AM
Aman Rana
Aman Rana - avatar
0
Ok but can't help without code
5th Jan 2021, 12:08 PM
Nihar Buliya
Nihar Buliya - avatar
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";     }
5th Jan 2021, 2:41 PM
Aman Rana
Aman Rana - avatar
0
The bug is happening here
5th Jan 2021, 2:41 PM
Aman Rana
Aman Rana - avatar
0
The value of p and j is not getting incremented
5th Jan 2021, 2:41 PM
Aman Rana
Aman Rana - avatar