Skip to content

Commit 1013dfc

Browse files
committed
1u
1 parent 69cc407 commit 1013dfc

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

Diff for: cpp/1.cpp

+7-15
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,22 @@
33
namespace {
44
long p1(const auto &input) {
55
long m{0};
6-
long c{0};
7-
for (const auto &l : input) {
8-
if (l.empty()) {
9-
m = std::max(m, c);
10-
c = 0;
11-
} else {
12-
c += std::atol(l.c_str());
13-
}
6+
for (long c{}; const auto &l : input) {
7+
c = l.empty() ? 0 : c + std::atol(l.c_str());
8+
m = std::max(m, c);
149
}
15-
return std::max(m, c);
10+
return m;
1611
}
1712

1813
long p2(const auto &input) {
19-
std::vector<long> m{};
20-
long c{0};
14+
std::vector<long> m{0};
2115
for (const auto &l : input) {
2216
if (l.empty()) {
23-
m.emplace_back(-c);
24-
c = 0;
17+
m.emplace_back(0);
2518
} else {
26-
c += std::atol(l.c_str());
19+
m.back() += -std::atol(l.c_str());
2720
}
2821
}
29-
m.emplace_back(-c);
3022
std::sort(m.begin(), m.end());
3123
return std::abs(m[0] + m[1] + m[2]);
3224
}

0 commit comments

Comments
 (0)