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
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
int main()
{
std::vector<std::string> jan(31, "Jan");
//for (const auto & elem : jan)std::cout << elem << " ";std::cout << "\n";
std::cout << "jan size: " << jan.size() << "\n";//sanity checks
std::vector<std::string> marTodec{306};
auto itr = marTodec.begin();
std::fill(marTodec.begin(), itr + 31, "Mar");
itr += 31;
std::fill(itr, itr + 30, "Apr");
itr += 30;
std::fill(itr, itr+31, "May");
itr += 31;
std::fill(itr, itr+30, "Jun");
itr += 30;
std::fill(itr, itr+31, "Jul");
itr += 31;
std::fill(itr, itr+31, "Aug");
itr += 31;
std::fill(itr, itr+30, "Sep");
itr += 30;
std::fill(itr, itr + 31, "Oct");
itr += 31;
std::fill(itr, itr+30, "Nov");
itr+= 30;
std::fill(itr, itr+31, "Dec");
// for (const auto& elem : marTodec) std::cout << elem << " ";std::cout << "\n";
std::cout << "marTodec size: " << marTodec.size() << "\n";
bool leap = true;
if(leap)
{
std::vector<std::string> feb(29, "feb");
// std::cout << "feb size: " << feb.size() << "\n";
std::vector<std::string> year {};
year.reserve(jan.size() + feb.size() + marTodec.size());
year.insert(year.end(), std::make_move_iterator(jan.begin()), std::make_move_iterator(jan.end()));
year.insert(year.end(), std::make_move_iterator(feb.begin()), std::make_move_iterator(feb.end()));
year.insert(year.end(), std::make_move_iterator(marTodec.begin()), std::make_move_iterator(marTodec.end()));
std::cout << "year size: " << year.size() << "\n";
//for (const auto& elem : year)std::cout << elem << " "; std::cout << "\n";
std::cout << "Enter day of the year \n";
size_t day{};
std::cin >> day;
auto itrMonth = std::find(year.begin(), year.end(), year[day-1]);
auto itrDay = year.begin() + day;
std::cout << "The day is: " << year[day - 1] << " " << std::distance(itrMonth, itrDay);
}
else
{
std::vector<std::string> feb(28, "feb");
// std::cout << "feb size: " << feb.size() << "\n";
std::vector<std::string> year {};
year.reserve(jan.size() + feb.size() + marTodec.size());
year.insert(year.end(), std::make_move_iterator(jan.begin()), std::make_move_iterator(jan.end()));
year.insert(year.end(), std::make_move_iterator(feb.begin()), std::make_move_iterator(feb.end()));
year.insert(year.end(), std::make_move_iterator(marTodec.begin()), std::make_move_iterator(marTodec.end()));
std::cout << "year size: " << year.size() << "\n";
//for (const auto& elem : year)std::cout << elem << " "; std::cout << "\n";
std::cout << "Enter day of the year \n";
size_t day{};
std::cin >> day;
auto itrMonth = std::find(year.begin(), year.end(), year[day-1]);
auto itrDay = year.begin() + day;
std::cout << "The day is: " << year[day - 1] << " " << std::distance(itrMonth, itrDay);
}
}
|