summaryrefslogtreecommitdiff
path: root/2017/9.c
blob: 3e30c168b5881215617ac8b8264b89e0752f2217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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);
}