-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday02b.c
38 lines (34 loc) · 812 Bytes
/
day02b.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "common.h"
typedef struct Policy {
int pos0;
int pos1;
char c;
} Policy_t;
_Bool validate (char const * pass, Policy_t policy) {
int n_c = 0;
if (pass[policy.pos0-1] == policy.c) {
++n_c;
}
if (pass[policy.pos1-1] == policy.c) {
++n_c;
}
return (n_c == 1);
}
int main (int argc, char ** argv) {
int n_valid = 0;
do {
Policy_t policy;
char password [256];
int ret = scanf("%i-%i %c: %255s", &(policy.pos0), &(policy.pos1), &(policy.c), &(password[0]));
if (ret == 4) {
if (validate(password, policy)) {
++n_valid;
}
} else if (ret == EOF) {
break;
} else {
ERROR("scanf failed");
}
} while (1);
DISP(n_valid);
}