-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17.cpp
43 lines (38 loc) · 1023 Bytes
/
17.cpp
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 <iostream>
// one, two, three, four, five, six, seven, eight, nine
const std::uint32_t units[10] = {0, 3, 3, 5, 4, 4, 3, 5, 5, 4};
// eleven, twelve, thirteen, fourteen, fifteen,
// sixteen, seventeen, eighteen, nineteen
const std::uint32_t teens[10] = {0, 6, 6, 8, 8, 7, 7, 9, 8, 8};
// ten, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety
const std::uint32_t tens[10] = {0, 3, 6, 6, 5, 5, 5, 7, 6, 6};
constexpr std::uint32_t one_thousand = 11;
inline std::uint32_t count(int n) {
std::uint32_t ans = 0;
int unit = n % 10;
ans += units[unit];
n /= 10;
if (n) {
int ten = n % 10;
if (ten == 1 && unit != 0) {
ans -= units[unit];
ans += teens[unit];
} else {
ans += tens[ten];
}
n /= 10;
if (n) {
ans += units[n % 10] + 7;
if (unit || ten) ans += 3;
}
}
return ans;
}
int main() {
std::uint32_t ans = one_thousand;
for (int i = 1; i < 1000; ++i) {
ans += count(i);
// std::cout << i << ": " << count(i) << std::endl;
}
std::cout << ans << std::endl;
}