refactor: make list more generic

This commit is contained in:
2023-12-03 12:51:53 +01:00
parent db2c43032f
commit b88ad0abf9
4 changed files with 77 additions and 71 deletions

11
day_2.c
View File

@@ -2,6 +2,8 @@
// Created by Lennart on 02/12/2023.
//
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -18,7 +20,9 @@ int bufferLen;
#ifdef _WIN32
#define STRTOK_TS strtok_s
#else
#elif defined(__STDC_LIB_EXT1__)
#define STRTOK_TS strtok_s
#elif _SVID_SOURCE || _BSD_SOURCE || _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
#define STRTOK_TS strtok_r
#endif //_WIN32
@@ -39,12 +43,12 @@ void main() {
char *sets = &line[strlen("Game : ") + (int) floor(log10(abs(gameId))) + 1];
char *set_context;
const char *set = STRTOK_TS(sets, ";", &set_context);
char *set = STRTOK_TS(sets, ";", &set_context);
int maxRed = 0, maxGreen = 0, maxBlue = 0;
bool fits = true;
while(set != NULL) {
const char *cube = strtok(set, ",");
char *cube = strtok(set, ",");
int red = 0, green = 0, blue = 0;
while(cube != NULL) {
int amount;
@@ -67,6 +71,7 @@ void main() {
maxBlue = blue > maxBlue ? blue : maxBlue;
set = STRTOK_TS(NULL, ";", &set_context);
free(cube);
}
result1 += fits ? gameId : 0;