From 0fefcad511bd80d4a84b11063aef95bbf6b42306 Mon Sep 17 00:00:00 2001
From: Vedant Shrivastava <vedantshrivastava466@gmail.com>
Date: Tue, 5 Oct 2021 18:00:52 +0530
Subject: [PATCH] Create _12.cpp

---
 cpp/_12.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 cpp/_12.cpp

diff --git a/cpp/_12.cpp b/cpp/_12.cpp
new file mode 100644
index 0000000000..c8fa52707e
--- /dev/null
+++ b/cpp/_12.cpp
@@ -0,0 +1,40 @@
+class Solution {
+public:
+    string intToRoman(int num) {
+        // Prepare ordered dictionary with array and pair
+        pair<int,string> rmap[] = {
+            {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"}
+        };
+
+        // Initialize pointer to the beginning of the array
+        int rptr = 0;
+        string str="";
+        // Loop till the number is above 0
+        while(num){
+            // If numeric value at pointer is >= the number
+            if(num>=(rmap[rptr]).first){
+                // Add numeral to the answer
+                str += (rmap[rptr]).second;
+                // subtract numeric value from the number
+                num -= (rmap[rptr]).first;
+            }
+            else{
+                // Move pointer to the next biggest numeric value
+                rptr++;
+            }
+        }
+        return str;
+    }
+};