From 4af6c7b6549fb6f5a3b482d0a1b417e278e7916d Mon Sep 17 00:00:00 2001 From: Shiwani <97833337+Shiwani-sahu@users.noreply.github.com> Date: Tue, 25 Oct 2022 08:14:20 +0530 Subject: [PATCH] Create Integer-to-Roman.cpp --- Leetcode/Integer-to-Roman.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Leetcode/Integer-to-Roman.cpp diff --git a/Leetcode/Integer-to-Roman.cpp b/Leetcode/Integer-to-Roman.cpp new file mode 100644 index 0000000..2afc62a --- /dev/null +++ b/Leetcode/Integer-to-Roman.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + string intToRoman(int num) { + vector>m{{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"} }; + + string s=""; + for(auto i:m) + { + while(num>=i.first) + { + s=s+i.second; + num-=i.first; + } + } + return s; + + } +};