-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchallenge.cpp
More file actions
35 lines (29 loc) · 934 Bytes
/
challenge.cpp
File metadata and controls
35 lines (29 loc) · 934 Bytes
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
//
// challenge.cpp
// Challenges
//
// Created by Carlos Álvaro on 28/02/2021.
// Copyright © 2021 cdalvaro. All rights reserved.
//
#include <algorithm>
#include "challenges/c0017/challenge.hpp"
#include "tools/types/named_number.hpp"
using namespace challenges;
using namespace tools::types;
Challenge17::Challenge17(const std::size_t &first, const std::size_t &last) : first(first), last(last) {
}
IChallenge::Solution_t Challenge17::solve() {
Type_t sum = 0;
for (auto number = first; number <= last; ++number) {
auto name = NamedNumber(number).getName();
removeAllOccurrencesOf(name, {' ', '-'});
sum += name.size();
}
return sum;
}
void Challenge17::removeAllOccurrencesOf(std::string &str, const std::set<char> &characters) {
for (auto character : characters) {
auto it = std::remove(str.begin(), str.end(), character);
str.erase(it, str.end());
}
}