Created
December 23, 2015 18:18
-
-
Save ta1hia/adfcb57ba05df1d660a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
int nbytes, ncases, i, j, k; | |
char c, res; | |
char ** msgs; | |
scanf("%d", &ncases); | |
msgs = malloc(ncases * sizeof(char *)); | |
for (i = 0; i < ncases; i++) { | |
scanf("%d", &nbytes); | |
msgs[i] = malloc(nbytes+1); | |
for (j = 0; j < nbytes; j++) { | |
res = 0; | |
for (k = 0; k < 8; k++) { | |
scanf(" %c", &c); | |
if (c == 'O') | |
res = res << 1; | |
else if (c == 'I') | |
res = (res << 1) | 1; | |
} | |
msgs[i][j] = res; | |
} | |
msgs[i][nbytes+1] = '\0'; | |
} | |
for (i = 0; i < ncases; i++) { | |
printf("Case #%d: %s", i, msgs[i]); | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment