aoc-2020/jour2/main.c

61 lines
1.1 KiB
C
Raw Permalink Normal View History

2020-12-09 16:48:45 +01:00
#include <stdio.h>
#include <stdlib.h>
2020-12-14 01:18:07 +01:00
void deux_partie(FILE *ptr)
2020-12-09 16:48:45 +01:00
{
2020-12-14 01:18:07 +01:00
int born_inf, born_sup;
2020-12-09 16:48:45 +01:00
int find = 0;
2020-12-14 01:18:07 +01:00
char spe_char;
2020-12-09 16:48:45 +01:00
char word[256];
2020-12-14 01:18:07 +01:00
fscanf(ptr, "%d-%d %c: %s", &born_inf, &born_sup, &spe_char, word);
2020-12-09 16:48:45 +01:00
while (!feof(ptr))
{
2020-12-14 01:18:07 +01:00
if ((word[born_inf - 1] == spe_char && word[born_sup - 1] != spe_char)
|| (word[born_inf - 1] != spe_char && word[born_sup - 1] == spe_char))
2020-12-09 16:48:45 +01:00
{
find++;
}
2020-12-14 01:18:07 +01:00
fscanf(ptr, "%d-%d %c: %s", &born_inf, &born_sup, &spe_char, word);
2020-12-09 16:48:45 +01:00
}
printf("%d bons mdp trouvés.\n", find);
}
2020-12-14 01:18:07 +01:00
void prem_partie(FILE *ptr)
2020-12-09 16:48:45 +01:00
{
2020-12-14 01:18:07 +01:00
int born_inf, born_sup, i, nbOcc;
2020-12-09 16:48:45 +01:00
int find = 0;
2020-12-14 01:18:07 +01:00
char spe_char, read_char;
2020-12-09 16:48:45 +01:00
char word[256];
2020-12-14 01:18:07 +01:00
fscanf(ptr, "%d-%d %c: %s", &born_inf, &born_sup, &spe_char, word);
2020-12-09 16:48:45 +01:00
while (!feof(ptr))
{
i = 0;
nbOcc = 0;
2020-12-14 01:18:07 +01:00
read_char = word[i];
while (read_char != '\0')
2020-12-09 16:48:45 +01:00
{
2020-12-14 01:18:07 +01:00
if (read_char == spe_char)
2020-12-09 16:48:45 +01:00
{
nbOcc++;
}
i++;
2020-12-14 01:18:07 +01:00
read_char = word[i];
2020-12-09 16:48:45 +01:00
}
2020-12-14 01:18:07 +01:00
if (nbOcc >= born_inf && nbOcc <= born_sup)
2020-12-09 16:48:45 +01:00
{
find++;
}
2020-12-14 01:18:07 +01:00
fscanf(ptr, "%d-%d %c: %s", &born_inf, &born_sup, &spe_char, word);
2020-12-09 16:48:45 +01:00
}
printf("%d bons mdp trouvés.\n", find);
}