uppga.c (782B)
1 #include "common.h" 2 3 int main(int argc, char **argv) { 4 char **lines; 5 size_t nlines = readlines(&lines, "input"); 6 7 size_t i, j, sum = 0; 8 smallset a, b, c; 9 smallset_init(&a, ASIZE); 10 smallset_init(&b, ASIZE); 11 smallset_init(&c, ASIZE); 12 for (i = 0; i < nlines; i++) { 13 size_t slen = strlen(lines[i]); 14 if (lines[i][slen - 1] == '\n') 15 slen--; 16 17 for (j = 0; j < slen / 2; j++) 18 smallset_insert(&a, map(lines[i][j])); 19 for (j = slen / 2; j < slen; j++) 20 smallset_insert(&b, map(lines[i][j])); 21 smallset_intersection(&c, &a, &b); 22 23 sum += prio(smallset_getone(&c)); 24 25 smallset_empty(&c); 26 smallset_empty(&b); 27 smallset_empty(&a); 28 } 29 smallset_clear(&a); 30 smallset_clear(&b); 31 smallset_clear(&c); 32 33 printf("sum: %zu\n", sum); 34 }