28 lines
535 B
C
28 lines
535 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(void) {
|
|
FILE *fp;
|
|
char* line = NULL;
|
|
size_t len = 0;
|
|
int valid = 0;
|
|
|
|
fp = fopen("input", "r");
|
|
|
|
while(getline(&line, &len, fp) != -1) {
|
|
int start, end;
|
|
char subject;
|
|
char* password;
|
|
|
|
sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password);
|
|
|
|
if(password[start - 1] == subject && password[end - 1] != subject ||
|
|
password[end - 1] == subject && password[start - 1] != subject)
|
|
valid++;
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
printf("There are %d valid passwords\n", valid);
|
|
}
|