1
0
Fork 0

03: Solve in C

This commit is contained in:
Mia Herkt 2022-12-03 19:03:40 +01:00
parent 4f8b582364
commit b2a7be43ea
Signed by: mia
GPG key ID: 72E154B8622EC191
2 changed files with 33 additions and 1 deletions

View file

@ -297,4 +297,4 @@ HqSJchHTHbTgHhGhvmRzFmnFtzRF
RJqHTpgDLJDSqLJJPNVjsfPwBVsVLlfN
NDrBlSmrFBlbbJllmtHHwhNNhZztqHVRzQ
CMTCGLcvvtfCdCcCvCnMTMcTzjHwVZVRLjRRjQjRHRwzwjVH
dfGdgGMGPggnvfvgbtDtlSJPDSFJPslJ
dfGdgGMGPggnvfvgbtDtlSJPDSFJPslJ

32
03/solution.c Normal file
View file

@ -0,0 +1,32 @@
#include <stdio.h>
#include <string.h>
#define P(c) (c < 97 ? c - 38 : c - 96)
int main(void) {
char l[128];
int e = 0, i, n, S = 0, G = 0, g[53] = {0};
while (fgets(l, 128, stdin)) {
n = strlen(l) - 1;
int s[53] = {0};
for (i = 0; i < n / 2; i++) s[P(l[i])] = 1;
for (i = n / 2; i < n; i++) s[P(l[i])] *= 2;
for (i = 1; i < 53; i++) if (s[i] > 1) S += i;
if (!(e % 3))
for (i = 0; i < n; i++) g[P(l[i])] = 1;
else {
for (i = 0; i < n; i++) g[P(l[i])] *= 2;
for (i = 1; i < 53; i++) g[i] = g[i] > 1;
}
if (!(++e % 3)) {
for (i = 1; i < 53; i++) if (g[i]) G += i;
memset(g, 0, 53 * sizeof(int));
}
}
printf("Silver: %d\nGold: %d\n", S, G);
}