diff options
Diffstat (limited to '2017/9.c')
-rw-r--r-- | 2017/9.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/2017/9.c b/2017/9.c new file mode 100644 index 0000000..3e30c16 --- /dev/null +++ b/2017/9.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <stdbool.h> + + +int main(void){ + freopen("9.in","r",stdin); + + int c; + int depth=0,score=0,removed=0; + bool garbage=false; + while((c=getchar())!=EOF){ + if(garbage){ + switch(c){ + case '!': + if(garbage)getchar(); + break; + case '>': + garbage=false; + break; + default: + if(garbage)removed++; + } + } else { + switch(c){ + case '{': + if(!garbage){ + depth++; + score+=depth; + } + break; + case '}': + if(!garbage)depth--; + break; + case '<': + garbage=true; + break; + } + } + } + + printf("%d\n",score); + printf("%d\n",removed); +} |