From 6d176569fd64464f1529eecc522b4bfebeeff18f Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 2 Dec 2020 00:09:58 -0500 Subject: Solve day 2 part 2 --- 2020/day02.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to '2020/day02.c') diff --git a/2020/day02.c b/2020/day02.c index 597efde..793396c 100644 --- a/2020/day02.c +++ b/2020/day02.c @@ -1,7 +1,7 @@ #include #include int main(void) { - int valid = 0; + int valid1 = 0, valid2 = 0; int l, u; char c, p[256]; while (EOF != scanf("%d-%d %c: %s\n", &l, &u, &c, p)) { @@ -9,7 +9,9 @@ int main(void) { for (int i = 0; p[i]; ++i) { if (p[i] == c) n++; } - if (n >= l && n <= u) valid++; + if (n >= l && n <= u) valid1++; + if ((p[l-1] == c) ^ (p[u-1] == c)) valid2++; } - printf("%d\n", valid); + printf("%d\n", valid1); + printf("%d\n", valid2); } -- cgit 1.4.1