uppgb.c (936B)
1 #include "common.h" 2 3 int cmp(const void *a, const void *b) { 4 lori *al = *((lori **)a); 5 lori *bl = *((lori **)b); 6 int c = compare(al, bl); 7 return c; 8 } 9 10 int main(int argc, char **argv) { 11 char **lines; 12 size_t nlines = readlines(&lines, "input"); 13 14 lori *loris[nlines + 2]; 15 lori *sig[2]; 16 17 char *next = lines[0]; 18 loris[0] = parseline("[[2]]", &next); 19 loris[1] = parseline("[[6]]", &next); 20 sig[0] = parseline("[[2]]", &next); 21 sig[1] = parseline("[[6]]", &next); 22 23 size_t i; 24 size_t c = 2; 25 for (i = 0; i < nlines; i++) { 26 if (strlen(lines[i]) > 1) { 27 loris[c] = parseline(lines[i], &next); 28 c++; 29 } 30 } 31 32 uint64_t sigidx[2] = {UINT64_MAX}; 33 qsort(loris, c, sizeof(*loris), cmp); 34 35 for (i = 0; i < c; i++) { 36 if (compare(loris[i], sig[0]) == 0) 37 sigidx[0] = i; 38 else if (compare(loris[i], sig[1]) == 0) 39 sigidx[1] = i; 40 } 41 printf("%llu\n", (sigidx[0] + 1) * (sigidx[1] + 1)); 42 }