blob: 50124aed16460da9137dc4c8b449e05d143ce1af (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include <stdio.h>
#include <stdlib.h>
int main (void) {
size_t cap = 0;
char *buf = NULL;
unsigned groups1[512] = {0};
unsigned groups2[512] = {~0};
for (int i = 0; 0 < getline(&buf, &cap, stdin);) {
if (buf[0] == '\n') {
i++;
groups2[i] = ~0;
continue;
}
unsigned group2 = 0;
for (char *ch = buf; *ch && *ch != '\n'; ++ch) {
groups1[i] |= 1 << (*ch - 'a');
group2 |= 1 << (*ch - 'a');
}
groups2[i] &= group2;
}
int sum = 0;
for (int i = 0; i < 512; ++i) {
sum += __builtin_popcount(groups1[i]);
}
printf("%d\n", sum);
sum = 0;
for (int i = 0; i < 512; ++i) {
sum += __builtin_popcount(groups2[i]);
}
printf("%d\n", sum);
}
|