diff --git a/cpp/more/0012.cpp b/cpp/more/0012.cpp new file mode 100644 index 0000000..b5348c1 --- /dev/null +++ b/cpp/more/0012.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +class Solution { +private: + const inline static std::vector> RN = { + {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, + {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, + {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, + {"", "M", "MM", "MMM"} + }; +public: + static std::string intToRoman(int num) { + return RN[3][num / 1000] + + RN[2][(num / 100) % 10] + + RN[1][(num % 100) / 10] + + RN[0][num % 10]; + } +}; + +int main() { + std::cout << Solution::intToRoman(1994); + return 0; +}