Raju the fan of Great Mathematician Ramanujan developed an encoder that encodes the first 16 lowercase English letters using 4 bits each. The first bit (from the left) of the code is 0 if the letter lies among the first 8 letters, else it is 1, signifying that it lies among the last 8 letters.
#include <stdio.h>
#include <math.h>
int main()
{
int t, n, i, j, k, sum=0;
scanf("%d", &t);
for(i=0;i<t;i++){
scanf("%d", &n);
char s[n];
scanf("%s", s);
for(j=0;j<n/4;j++){
for(k=j*4+1;k<j*4+4+1;k++){
if(s[k-1]=='1') {
sum = sum + pow(2, 4*j-(k-4));
}
}
printf("%c", sum+97);
sum = 0;
}
printf("\n");
}
return 0;
}
Comments
Post a Comment