Encoded String : SLOUTION IN C ( EXPERT SOLUTION @KAPILSIR)
LINK OF QUESTION ON CODECHEF : https://www.codechef.com/JAN21C/problems/DECODEIT
LINK OF VIDEO EXPLAINAtioN : https://youtu.be/q5r0Onm_YsM
#include <stdio.h>
#include <math.h>
int main(void) {
int t;
scanf("%d",&t);
while(t!=0){
int n;
scanf("%d",&n);
int A[n];
for(int i=1; i<=n; i++){
scanf("%1d",&A[i]);
if(i%4 == 0){
int dec = 0;
for(int j=i,k=0; j>(i-4); j--,k++){
dec += A[j] * pow(2, k);
}
printf("%c",97+dec);
}
}
t--;
printf("\n");
}
return 0;
}
Details about Encoded String Codechef January 2021 Question :
Input:
The first line of the input contains an integer T, denoting the number of test cases.
The first line of each test case contains an integer N, the length of the encoded string.
The second line of each test case contains the encoded string S.
Output:
For each test case, print the decoded string, in a separate line.
Constraints
1≤T≤10
4≤N≤105
The length of the encoded string is a multiple of 4.
0≤Si≤1
Subtasks
100 points : Original constraints.
Sample Input:
3
4
0000
8
00001111
4
1001
Sample Output:
a
ap
j