add third day

This commit is contained in:
Antonia 2022-12-03 15:54:25 +01:00
parent a3e682fea3
commit bb38310111
2 changed files with 75 additions and 0 deletions

37
03.c Normal file
View file

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_prio (char c) {
int r = (int) (c - 'a'+1);
if (r > 0) return r;
return r + 'A' - 7;
}
int main () {
char cur[50];
int half = 0;
u_int64_t mask = 0;
int sum = 0;
while (fgets(cur,50,stdin) != NULL) {
int i;
half = strlen(cur) / 2;
for (i = 0; i<half; i++) {
//printf("%c %d\n", cur[i], get_prio(cur[i]));
mask |= (1LL << get_prio(cur[i]));
}
//printf("half!\n");
for (i=half; i<strlen(cur)-1; i++) {
//printf("%c %d\n", cur[i], get_prio(cur[i]));
if (mask & (1LL << get_prio(cur[i]))) {
// printf("%c", cur[i]);
sum += get_prio(cur[i]);
break;
}
}
mask = 0;
}
printf("%d\n", sum);
}

38
03_02.c Normal file
View file

@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_prio (char c) {
int r = (int) (c - 'a'+1);
if (r > 0) return r;
return r + 'A' - 7;
}
int main () {
char cur[50];
int half = 0;
u_int64_t masks[3] = {0};
int sum = 0;
int j =0;
while (fgets(cur,50,stdin) != NULL) {
int i;
for (i=0; i<strlen(cur)-1; i++) {
masks[j] |= (1LL << get_prio(cur[i]));
}
if (j == 2) {
u_int64_t mask = 0;
mask = masks[0] & masks[1] & masks[2];
for (int k=0; k<3; k++) masks[k] = 0;
int k =-1;
while (mask > 0) {
k++;
mask >>=1LL;
}
sum += k;
j = -1;
}
j++;
}
printf("%d\n", sum);
}