From 5815a57f778208ec9b868305207cf82b138a07f2 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Sun, 21 Jun 2026 20:22:28 +0000 Subject: [PATCH] [Sync Iteration] cpp/roman-numerals/1 --- .../cpp/roman-numerals/1/roman_numerals.cpp | 31 +++++++++++++++++++ .../cpp/roman-numerals/1/roman_numerals.h | 9 ++++++ 2 files changed, 40 insertions(+) create mode 100644 solutions/cpp/roman-numerals/1/roman_numerals.cpp create mode 100644 solutions/cpp/roman-numerals/1/roman_numerals.h diff --git a/solutions/cpp/roman-numerals/1/roman_numerals.cpp b/solutions/cpp/roman-numerals/1/roman_numerals.cpp new file mode 100644 index 0000000..f9094ba --- /dev/null +++ b/solutions/cpp/roman-numerals/1/roman_numerals.cpp @@ -0,0 +1,31 @@ +#include "roman_numerals.h" +#include +#include + +using namespace std; + +namespace roman_numerals { + +string convert(int number) { + string roman = ""; + + // Diccionario estático de equivalencias + const vector> roman_mapping = { + {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"} + }; + + // Algoritmo Greedy + for (const auto& mapping : roman_mapping) { + while (number >= mapping.first) { + roman += mapping.second; // Concatenamos el símbolo + number -= mapping.first; // Reducimos el valor del número + } + } + + return roman; +} + +} diff --git a/solutions/cpp/roman-numerals/1/roman_numerals.h b/solutions/cpp/roman-numerals/1/roman_numerals.h new file mode 100644 index 0000000..2338dd1 --- /dev/null +++ b/solutions/cpp/roman-numerals/1/roman_numerals.h @@ -0,0 +1,9 @@ +#pragma once +#include + +namespace roman_numerals { + + // Traduce un entero arábigo a su equivalente romano + std::string convert(int number); + +}