Initial commit
This commit is contained in:
commit
f242d2b0df
420 changed files with 62521 additions and 0 deletions
32
2021/day02/day02.c
Normal file
32
2021/day02/day02.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char instr[9] = {0};
|
||||
int n = 0;
|
||||
|
||||
int pos = 0;
|
||||
int depth = 0;
|
||||
int aim = 0;
|
||||
|
||||
while (scanf("%s %d\n", instr, &n) == 2) {
|
||||
switch (instr[0]) {
|
||||
case 'd':
|
||||
aim += n;
|
||||
break;
|
||||
case 'u':
|
||||
aim -= n;
|
||||
break;
|
||||
case 'f':
|
||||
pos += n;
|
||||
depth += aim * n;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unknown instruction: %s", instr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("%d\n", pos * aim);
|
||||
printf("%d\n", pos * depth);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue