-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswer_to_you.cpp
More file actions
94 lines (86 loc) · 1.85 KB
/
answer_to_you.cpp
File metadata and controls
94 lines (86 loc) · 1.85 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <type_traits>
#include <vector>
#include <exception>
#include <algorithm>
#include <string>
#include <boost/lexical_cast.hpp>
namespace Answer
{
namespace _1
{
namespace Impl
{
template<typename Container>
auto mean_of(Container&& _data)
{
if (_data.size() == 0) { throw std::logic_error("Empty container"); }
using value_type = std::enable_if_t
<
std::is_arithmetic
<
std::remove_reference_t<Container>::value_type
>::value,
std::remove_reference_t<Container>::value_type
>;
value_type result{};
for (const auto& val : _data) { result += val; }
return static_cast<value_type>(result / _data.size());
}
}
void exec(void)
{
using ValueType = int;
std::vector<int> data;
while (true)
{
std::string input;
std::getline(std::cin, input);
if (input.empty()) { break; }
try
{
data.push_back(boost::lexical_cast<ValueType>(input));
}
catch (const boost::bad_lexical_cast& _blc)
{
data.push_back(static_cast<ValueType>(0));
}
}
std::cout << Impl::mean_of(data) << std::endl;
}
}
namespace _2
{
namespace Impl
{
template<typename String>
void to_upper(String& _origin)
{
using std::cbegin;
using std::cend;
using std::begin;
std::transform(cbegin(_origin), cend(_origin), begin(_origin), [](const auto& c) {return std::toupper(c, std::locale()); });
}
}
void exec(void)
{
std::vector<std::string> data;
while (true)
{
std::string input;
std::getline(std::cin, input);
if (input.empty()) { break; }
data.push_back(input);
}
for (auto& line : data) { Impl::to_upper(line); }
for (const auto& line : data) { std::cout << line << std::endl; }
}
}
}
#include <cstdlib>
int main(void)
{
Answer::_1::exec();
Answer::_2::exec();
std::system("pause");
}