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
|
#include <iostream>
#include <string>
#include <map>
int main()
{
std::map<std::string, int> temp {{{"Jan.", 1},
{"Feb.", 2},
{"Mar.", 3},
{"Apr.", 4},
{"May.", 5},
{"Jun.", 6},
{"Jul.", 7},
{"Aug.", 8},
{"Sep.", 9},
{"Oct.", 10},
{"Nov.", 11},
{"Dec.", 12}}};
// Sort by number (Map sorting hackery)
std::map<int, std::string> months;
for (auto iter = temp.begin(); iter != temp.end(); ++iter)
{
months.insert(std::pair<int, std::string>(iter->second, iter->first));
}
// Standard printing (First the spelling then the numbers)
for (auto iter = months.begin(); iter != months.end(); ++iter)
{
std::cout << iter->second << " ";
}
std::cout << std::endl << " ";
for (auto iter = months.begin(); iter != months.end(); ++iter)
{
std::cout << iter->first << " ";
}
return 0;
}
|