Created
May 2, 2014 20:35
-
-
Save wjlafrance/f8a0b836cbb051825e68 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 "m.h" | |
#define NEXT_FIELD b=strchr(b,';')+1; | |
G g; | |
L l[8]; | |
R r[28]; | |
char a[1024]; | |
char *b = a; | |
main() { | |
FILE *i = fopen("input.txt", "r"); | |
fgets(a, 1024, i); | |
fclose(i); | |
sscanf(b, "%d;%d;", &g.p, &g.t); | |
NEXT_FIELD NEXT_FIELD | |
TIMES(g.p) { | |
l[i].b = (*b == 't'); NEXT_FIELD | |
if(!l[i].b) { | |
sscanf(b, "%d;%d;%d;%d;", &l[i].m, &l[i].c, &l[i].p, &l[i].t); | |
NEXT_FIELD NEXT_FIELD NEXT_FIELD NEXT_FIELD | |
} | |
} | |
TIMES(28) { | |
sscanf(b, "%d;", &r[i].o); NEXT_FIELD | |
r[i].m = (*b == 't'); NEXT_FIELD | |
sscanf(b, "%d;", &r[i].i); NEXT_FIELD | |
} | |
TIMES(16) { | |
sscanf(b, "%d", &g.a[i]); | |
NEXT_FIELD | |
} | |
TIMES(16) { | |
sscanf(b, "%d", &g.e[i]); | |
NEXT_FIELD | |
} | |
FILE *c = fopen("c.dat", "w"); | |
fwrite(&g, sizeof(G), 1, c); | |
fwrite(&l, sizeof(L), 8, c); | |
fwrite(&r, sizeof(R), 28, c); | |
fclose(c); | |
} |
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 "m.h" | |
G g; | |
L l[8]; | |
R r[28]; | |
main() { | |
FILE *c = fopen("c.dat", "r"); | |
fread(&g, sizeof(G), 1, c); | |
fread(&l, sizeof(L), 8, c); | |
fread(&r, sizeof(R), 28, c); | |
fclose(c); | |
FILE *d = fopen("output.txt", "w"); | |
fprintf(d, "%d;%d;", g.p, g.t); | |
TIMES(g.p) { | |
fprintf(d, "%s;", l[i].b ? "true" : "false"); | |
if(!l[i].b){ | |
fprintf(d, "%d;%d;%d;%d;", l[i].m, l[i].c, l[i].p, l[i].t); | |
} | |
} | |
TIMES(28) { | |
fprintf(d, "%d;%s;%d;", r[i].o, r[i].m ? "true" : "false", r[i].i); | |
} | |
TIMES(16) { fprintf(d, "%d;", g.a[i] != 255 ? g.a[i] : -1); } | |
TIMES(16) { fprintf(d, "%d;", g.e[i] != 255 ? g.e[i] : -1); } | |
fclose(d); | |
} |
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
#import <stdio.h> | |
#import <stdint.h> | |
#define TIMES(X) for(int i = 0; i < (X); i++) | |
typedef uint8_t U; | |
typedef struct { | |
U p; | |
U t; | |
U a[16]; | |
U e[16]; | |
} G; | |
typedef struct { | |
U b; | |
uint16_t m; | |
U c; | |
U p; | |
U t; | |
} L; | |
typedef struct { | |
int8_t o; | |
U m; | |
U i; | |
} R; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment