32 lines
593 B
C
32 lines
593 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(void) {
|
|
FILE *fp;
|
|
char line[255];
|
|
int valid = 0;
|
|
|
|
fp = fopen("input", "r");
|
|
|
|
if(fp == NULL) {
|
|
perror("Error opening file.");
|
|
return(-1);
|
|
}
|
|
|
|
while(fgets(line, sizeof(line), fp) != NULL) {
|
|
int start, end;
|
|
char subject;
|
|
char password[64];
|
|
|
|
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);
|
|
}
|