2
1
Fork 0

Day 2: Slightly simplify C solutions

Not sure why I did it that way. Maybe because I was originally
going to use strtol or something?
This commit is contained in:
Mia Herkt 2021-12-02 17:21:50 +01:00
parent 03f4a91463
commit d6bf929fc8
Signed by: mia
GPG key ID: 72E154B8622EC191
2 changed files with 4 additions and 14 deletions

View file

@ -1,18 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h>
int main(void) { int main(void) {
FILE *fp = fopen("input.txt", "r"); FILE *fp = fopen("input.txt", "r");
char buf[16] = {0}, *np; char buf[16] = {0};
unsigned n, h = 0, v = 0; unsigned n, h = 0, v = 0;
while (fgets(buf, 16, fp) != NULL) { while (fgets(buf, 16, fp) != NULL) {
np = strchr(buf, ' '); sscanf(buf, "%*s %u", &n);
assert(np != NULL);
np++;
sscanf(np, "%u", &n);
switch (buf[0]) { switch (buf[0]) {
case 'd': case 'd':

View file

@ -1,18 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h>
int main(void) { int main(void) {
FILE *fp = fopen("input.txt", "r"); FILE *fp = fopen("input.txt", "r");
char buf[16] = {0}, *np; char buf[16] = {0};
unsigned n, aim = 0, h = 0, v = 0; unsigned n, aim = 0, h = 0, v = 0;
while (fgets(buf, 16, fp) != NULL) { while (fgets(buf, 16, fp) != NULL) {
np = strchr(buf, ' '); sscanf(buf, "%*s %u", &n);
assert(np != NULL);
np++;
sscanf(np, "%u", &n);
switch (buf[0]) { switch (buf[0]) {
case 'd': case 'd':