-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.c
More file actions
60 lines (54 loc) · 1 KB
/
3.c
File metadata and controls
60 lines (54 loc) · 1 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <string.h>
static int score(const char *sack, int len)
{
int c, i, j;
for (i = len / 2; i < len; ++i)
{
c = sack[i];
for (j = 0; j < len / 2; ++j)
{
if (sack[j] == c)
{
int wat = c <= 'Z' ? (c - 'A' + 27) : c - 'a' + 1;
return wat;
}
}
}
return 0;
}
int main(void)
{
static char sack[26 * 2 + 1];
int s1 = 0, s2 = 0;
while (!feof(stdin))
{
unsigned long flag[3] = {0};
int i, j, l;
for (i = 0; i < 3; ++i)
{
fscanf(stdin, "%s ", sack);
l = strlen(sack);
s1 += score(sack, l);
for (j = 0; j < l; ++j)
{
int c = sack[j];
c = c <= 'Z' ? c - 'A' + 26 : c - 'a';
flag[i] |= 1ul << c;
}
}
flag[0] = flag[0] & flag[1] & flag[2];
for (i = 0; i < 2 * 26; ++i)
{
if (flag[0] & 1)
{
s2 += i + 1;
break;
}
flag[0] >>= 1;
}
}
printf("part1: %d\n", s1);
printf("part2: %d\n", s2);
return 0;
}