Skip to content

Instantly share code, notes, and snippets.

@ta1hia
Created December 23, 2015 18:18
Show Gist options
  • Save ta1hia/adfcb57ba05df1d660a2 to your computer and use it in GitHub Desktop.
Save ta1hia/adfcb57ba05df1d660a2 to your computer and use it in GitHub Desktop.
#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