diff --git a/contests/4contest/4.cpp b/contests/4contest/4.cpp index e69de29..33e436c 100644 --- a/contests/4contest/4.cpp +++ b/contests/4contest/4.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +struct Acc { + double sum = 0; + size_t count = 0; + + void operator()(double value) { + sum += value; + count++; + } +}; + +int main() { + std::vector data; + + double value; + while (std::cin >> value) data.push_back(value); + + size_t n = data.size(); + size_t first_cut = n / 10; + + auto it_begin = data.begin() + first_cut; + auto it_end = data.end() - first_cut; + + std::sort(it_begin, it_end); + + size_t min_cut = (it_end - it_begin) / 10; + + it_begin += min_cut; + it_end -= min_cut; + + Acc acc = std::for_each(it_begin, it_end, Acc()); + + std::cout << std::fixed << std::setprecision(10); + std::cout << acc.sum / acc.count << std::endl; + + return 0; +} \ No newline at end of file diff --git a/contests/7contest/5.cpp b/contests/7contest/5.cpp index e30358c..88bc642 100644 --- a/contests/7contest/5.cpp +++ b/contests/7contest/5.cpp @@ -4,7 +4,7 @@ public: virtual ~Figure() {} }; -class Rectangle : Figure { +class Rectangle : public Figure { int a; int b; public: @@ -19,7 +19,7 @@ public: } }; -class Triangle : Figure { +class Triangle : public Figure { int a; int b; int c; @@ -33,4 +33,18 @@ public: return false; } -}; \ No newline at end of file +}; + +// #include + +// int main() { +// Rectangle r1(10, 5), r2(10, 2), r3(10, 5), r4(5, 10); +// Triangle t1(1, 2, 3); +// Figure* f = &r1; + +// assert(!f->equals(&r2)); +// assert(f->equals(&r3)); +// assert(!f->equals(&r4)); +// assert(!f->equals(&t1)); +// assert(!f->equals(nullptr)); +// } \ No newline at end of file diff --git a/contests/8contest/5.cpp b/contests/8contest/5.cpp new file mode 100644 index 0000000..f597e18 --- /dev/null +++ b/contests/8contest/5.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include + +std::chrono::system_clock::time_point parse_date(const std::string& date_str) { + std::tm tm = {}; + std::istringstream ss(date_str); + ss >> std::get_time(&tm, "%Y-%m-%d"); + + return std::chrono::system_clock::from_time_t(std::mktime(&tm)); +} + +int days_between(const std::chrono::system_clock::time_point& start, const std::chrono::system_clock::time_point& end) { + auto duration = end - start; + + return std::chrono::duration_cast(duration).count() / 24; +} + +int main() { + int sum = 0; + + std::string date1, date2; + std::cin >> date1; + + while (std::cin >> date2) { + auto start = parse_date(date1); + auto end = parse_date(date2); + + sum += std::abs(days_between(start, end)); + + date1 = date2; + } + + std::cout << sum << std::endl; + + return 0; +} \ No newline at end of file