2020-12-12 15:59:48 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
2020-12-14 01:20:58 +01:00
|
|
|
|
void deux_partie(FILE *ptr)
|
2020-12-12 15:59:48 +01:00
|
|
|
|
{
|
2020-12-14 17:05:05 +01:00
|
|
|
|
int find = 0, tmp;
|
2020-12-14 01:20:58 +01:00
|
|
|
|
int nb_data = 0; // est incrémenté si arg bon
|
2020-12-14 15:49:53 +01:00
|
|
|
|
// ne pas changer l’ordre des deux tableaux sinon ça casse (jsp pk)
|
2020-12-14 01:20:58 +01:00
|
|
|
|
char value[10];
|
2020-12-14 11:42:31 +01:00
|
|
|
|
char key[3];
|
|
|
|
|
char *tmp_char = NULL;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
fscanf(ptr, "%s:%s", key, value);
|
|
|
|
|
|
|
|
|
|
while (!feof(ptr))
|
|
|
|
|
{
|
|
|
|
|
if (!strncmp(key, "byr", 3))
|
|
|
|
|
{
|
|
|
|
|
tmp = sub_digit(value);
|
|
|
|
|
if (tmp >= 1920 && tmp <= 2002)
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data++;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
}
|
|
|
|
|
else if (!strncmp(key, "iyr", 3))
|
|
|
|
|
{
|
|
|
|
|
tmp = sub_digit(value);
|
|
|
|
|
if (tmp >= 2010 && tmp <= 2020)
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data++;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
}
|
|
|
|
|
else if (!strncmp(key, "eyr", 3))
|
|
|
|
|
{
|
|
|
|
|
tmp = sub_digit(value);
|
|
|
|
|
if (tmp >= 2020 && tmp <= 2030)
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data++;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
}
|
|
|
|
|
else if (!strncmp(key, "hgt", 3))
|
|
|
|
|
{
|
|
|
|
|
int checkH = sub_digit(value);
|
|
|
|
|
|
|
|
|
|
if (strstr(value, "cm") != NULL && checkH >= 150 && checkH <= 193)
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data++;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
else if (strstr(value, "in") != NULL && checkH >= 59 && checkH <= 76)
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data++;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
}
|
|
|
|
|
else if (!strncmp(key, "ecl", 3))
|
|
|
|
|
{
|
|
|
|
|
if (check_ecl(value))
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data++;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
}
|
|
|
|
|
else if (!strncmp(key, "pid", 3))
|
|
|
|
|
{
|
2020-12-14 11:42:31 +01:00
|
|
|
|
tmp_char = strpbrk(value, "0123456789");
|
|
|
|
|
if (strspn(tmp_char, "0123456789") == 9)
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data++;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
}
|
|
|
|
|
else if (!strncmp(key, "hcl", 3))
|
|
|
|
|
{
|
|
|
|
|
//comme le 1er char est :, on doit tout décaler de 1
|
|
|
|
|
if (value[1] == '#' && strlen(value) == 8)
|
|
|
|
|
{
|
|
|
|
|
int i = 2;
|
|
|
|
|
while (isalnum(value[i]) && value[i] != '\0')
|
|
|
|
|
i++;
|
|
|
|
|
|
2020-12-15 18:41:27 +01:00
|
|
|
|
if (i == (int) strlen(value))
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data++;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 17:05:05 +01:00
|
|
|
|
if (check_void_line(ptr))
|
2020-12-12 15:59:48 +01:00
|
|
|
|
{
|
2020-12-14 01:20:58 +01:00
|
|
|
|
if (nb_data == 7)
|
2020-12-12 15:59:48 +01:00
|
|
|
|
find++;
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data = 0;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(ptr, "%s:%s", key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("%d bons passeports trouvés.\n", find);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 01:20:58 +01:00
|
|
|
|
void prem_partie(FILE *ptr)
|
2020-12-12 15:59:48 +01:00
|
|
|
|
{
|
2020-12-14 17:05:05 +01:00
|
|
|
|
int find = 0;
|
2020-12-14 01:20:58 +01:00
|
|
|
|
int nb_data = 0, cid = 0;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
char word[256];
|
|
|
|
|
fscanf(ptr, "%s", word);
|
|
|
|
|
|
|
|
|
|
while (!feof(ptr))
|
|
|
|
|
{
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data++;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
|
|
|
|
|
if (!strncmp(word, "cid", 3))
|
|
|
|
|
cid = 1;
|
|
|
|
|
|
2020-12-14 17:05:05 +01:00
|
|
|
|
if (check_void_line(ptr))
|
2020-12-12 15:59:48 +01:00
|
|
|
|
{
|
2020-12-14 01:20:58 +01:00
|
|
|
|
if ((nb_data == 7 && !cid) || nb_data == 8)
|
2020-12-12 15:59:48 +01:00
|
|
|
|
find++;
|
2020-12-14 01:20:58 +01:00
|
|
|
|
nb_data = 0;
|
2020-12-12 15:59:48 +01:00
|
|
|
|
cid = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(ptr, "%s", word);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("%d bons passeports trouvés.\n", find);
|
|
|
|
|
}
|