repo.or.cz
/
aoc_eblake.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
day 25 optimize and improve heuristics
[aoc_eblake.git]
/
2017
/
advent9.c
blob
c1e933acb2197c117547489cba589d912089d344
1
#define _GNU_SOURCE 1
2
#include <stdio.h>
3
#include <string.h>
4
#include <stdlib.h>
5
#include <unistd.h>
6
7
int
main
(
void
)
8
{
9
int
depth
=
0
;
10
int
score
=
0
;
11
int
garbage
=
0
;
12
int
count
=
0
;
13
int
c
;
14
while
((
c
=
getchar
()) >=
0
)
15
if
(
garbage
) {
16
if
(
c
==
'!'
)
17
getchar
();
18
else if
(
c
==
'>'
)
19
garbage
=
0
;
20
else
21
count
++;
22
}
else
{
23
if
(
c
==
'{'
)
24
score
+= ++
depth
;
25
else if
(
c
==
'}'
)
26
depth
--;
27
else if
(
c
==
'<'
)
28
garbage
=
1
;
29
}
30
if
(
depth
)
31
printf
(
"oops
\n
"
);
32
printf
(
"score=%d garbage=%d
\n
"
,
score
,
count
);
33
return
0
;
34
}