Name | Language | Tokens Sum | Tokens Part 1 | Tokens Part 2 | Last change | |
---|---|---|---|---|---|---|
1 | LiquidFun | Python | 555 | 275 | 280 | 8 months ago |
2 | Valentin Slawicek | Kotlin | 1198 | 576 | 622 | 8 months ago |
3 | Visible-Bag4062 | C++ | 10473 | 473 | - | 9 months ago |
#include
<iostream>
#include
<map>
#include
<numeric>
#include
<string>
#include
<vector>
using
namespace
std
;
#define
A
(
i
,
j
)
adjs
.
push_back
(
{
i
,
j
}
)
;
#define
N
if
(
number
.
empty
(
)
)
char
dot
=
'
.
'
;
typedef
array
<
uint32_t
,
2
>
Pos
;
int
main
(
)
{
string
line
;
vector
<
string
>
grid
;
while
(
getline
(
cin
,
line
)
)
grid
.
push_back
(
line
)
;
Pos
dim
{
(
uint32_t
)
grid
.
size
(
)
,
(
uint32_t
)
grid
[
0
]
.
size
(
)
}
;
grid
.
insert
(
begin
(
grid
)
,
string
(
dim
[
1
]
,
dot
)
)
;
for
(
auto
it
=
begin
(
grid
)
;
it
!=
end
(
grid
)
;
++
it
)
*
it
=
dot
+
*
it
+
dot
;
map
<
Pos
,
char
>
symbols
;
map
<
Pos
,
vector
<
uint32_t
>
>
numbers
;
for
(
uint32_t
i
=
1
;
i
<
dim
[
0
]
+
1
;
++
i
)
{
vector
<
char
>
number
;
vector
<
Pos
>
adjs
;
for
(
uint32_t
j
=
1
;
j
<
dim
[
1
]
+
2
;
++
j
)
{
auto
g
=
grid
[
i
]
[
j
]
;
if
(
g
>
47
&&
g
<
58
)
{
N
{
A
(
i
-
1
,
j
-
1
)
;
A
(
i
,
j
-
1
)
;
A
(
i
+
1
,
j
-
1
)
;
}
number
.
push_back
(
g
)
;
A
(
i
-
1
,
j
)
;
A
(
i
+
1
,
j
)
;
continue
;
}
if
(
dot
!=
g
)
symbols
[
{
i
,
j
}
]
=
g
;
N
continue
;
A
(
i
-
1
,
j
)
;
A
(
i
,
j
)
;
A
(
i
+
1
,
j
)
;
uint32_t
n
=
0
;
for
(
auto
c
:
number
)
n
=
10
*
n
+
c
-
'
0
'
;
for
(
auto
adj
:
adjs
)
{
auto
it
=
numbers
.
find
(
adj
)
;
if
(
it
!=
end
(
numbers
)
)
it
->
second
.
push_back
(
n
)
;
else
numbers
[
adj
]
=
vector
<
uint32_t
>
{
n
}
;
}
number
.
clear
(
)
;
adjs
.
clear
(
)
;
}
}
uint64_t
sum
=
0
;
for
(
auto
sym
:
symbols
)
{
auto
it
=
numbers
.
find
(
sym
.
first
)
;
if
(
it
!=
end
(
numbers
)
)
sum
+=
accumulate
(
begin
(
it
->
second
)
,
end
(
it
->
second
)
,
0
)
;
}
cout
<<
sum
<<
endl
;
}