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
|
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
string solution(vector<int> t)
{
auto const season_days = t.size() / 4;
auto const winter = minmax_element(t.begin() + season_days * 0, t.begin() + season_days * 1);
auto const spring = minmax_element(t.begin() + season_days * 1, t.begin() + season_days * 2);
auto const summer = minmax_element(t.begin() + season_days * 2, t.begin() + season_days * 3);
auto const autumn = minmax_element(t.begin() + season_days * 3, t.begin() + season_days * 4);
struct { std::string name; int dt; } dts[4] =
{ { "WINTER", *winter.second - *winter.first }, { "SPRING", *spring.second - *spring.first },
{ "SUMMER", *summer.second - *summer.first }, { "AUTUMN", *autumn.second - *autumn.first }, };
return max_element(dts, dts + 4, [](auto a, auto b){ return a.dt < b.dt; })->name;
}
int main()
{
std::cout << solution({-3, -14, -5, 6, 8, 42, 8, 3}) << '\n';
std::cout << solution({2, -3, 3, 1, 10, 8, 2, 5, 13, -5, 3, -18}) << '\n';
}
| |