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 <iostream>
#include <string>
#include <utility>
std::string to_roman(int value)
{
static const std::pair<int, const char*> romandata[] = {
{1000, "M" }, {900, "CM"}, {500, "D" }, {400, "CD"}, {100, "C" },
{ 90, "XC"}, { 50, "L" }, { 40, "XL"}, { 10, "X" }, { 9, "IX"},
{ 5, "V" }, { 4, "IV"}, { 1, "I" },
};
std::string result;
for (const auto& current: romandata) {
while (value >= current.first) {
result += current.second;
value -= current.first;
}
}
return result;
}
int main()
{
for (int i = 1; i <= 4000; ++i) {
std::cout << to_roman(i) << '\n';
}
}
|