Progress in c
This commit is contained in:
49
2015/day01/day01.c
Normal file
49
2015/day01/day01.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void part1() {
|
||||
printf("Part 1\n");
|
||||
int floor = 0;
|
||||
char ch = getchar();
|
||||
while(ch) {
|
||||
if(ch == '\n') { break; }
|
||||
if(ch == '(') {
|
||||
floor++;
|
||||
} else if(ch == ')') {
|
||||
floor--;
|
||||
}
|
||||
ch = getchar();
|
||||
}
|
||||
printf("Final Floor: %d\n", floor);
|
||||
}
|
||||
|
||||
void part2() {
|
||||
printf("Part 2\n");
|
||||
int floor = 0, step = 0;
|
||||
char ch = getchar();
|
||||
while(ch) {
|
||||
step++;
|
||||
if(ch == '\n') { break; }
|
||||
if(ch == '(') {
|
||||
floor++;
|
||||
} else if(ch == ')') {
|
||||
floor--;
|
||||
}
|
||||
if(floor < 0) {
|
||||
break;
|
||||
}
|
||||
ch = getchar();
|
||||
}
|
||||
printf("Enter basement at: %d\n", step);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int doPart = 1;
|
||||
if(argc > 1) { doPart = argv[1][0] - '0'; }
|
||||
if(doPart == 1) {
|
||||
part1();
|
||||
} else {
|
||||
part2();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user