-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpretty_song.cpp
More file actions
68 lines (58 loc) · 1.53 KB
/
Copy pathpretty_song.cpp
File metadata and controls
68 lines (58 loc) · 1.53 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//============================================================================
// Name : test.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
bool is_vowel(char c)
{
switch ( c )
{
case 'I': case 'E': case 'A': case 'O': case 'U': case 'Y':
return true;
}
return false;
}
double calc_harmonic(size_t n)
{
static std::vector<double> harmonic_numbers;
if (harmonic_numbers.empty())
{
harmonic_numbers.reserve(500001);
harmonic_numbers.push_back(0);
for (size_t i = 1; i <= 500000; ++i)
harmonic_numbers.push_back(harmonic_numbers[i - 1] + 1.0 / double(i));
}
return harmonic_numbers[n];
}
double score(std::string const & title)
{
size_t start = 0;
double ret = 0, hn = 0;
for (auto left = title.begin(), right = title.end() - 1; left <= right; ++left, -- right)
{
hn += calc_harmonic(title.size() - start) - calc_harmonic(start);
start++;
if (is_vowel(*left))
{
ret += hn;
}
if (right != left && is_vowel(*right))
{
ret += hn;
}
}
return ret;
}
int main(int argc, char* argv[])
{
std::string title;
std::cin >> title;
std::cout << std::fixed << std::setprecision(7) << score(title) << std::endl;
return 0;
}