From 4f69640e402e4569c9739e8b2e1198dc3d6ca9fe Mon Sep 17 00:00:00 2001 From: Mayankseth Date: Fri, 27 Oct 2023 23:47:23 +0530 Subject: [PATCH] integer to Roman --- Leetcode/integertoRoman.cpp | 109 ++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Leetcode/integertoRoman.cpp diff --git a/Leetcode/integertoRoman.cpp b/Leetcode/integertoRoman.cpp new file mode 100644 index 0000000..dbfe385 --- /dev/null +++ b/Leetcode/integertoRoman.cpp @@ -0,0 +1,109 @@ +class Solution { +public: + string intToRoman(int num) { + string s ; + + int z,i=0; + while(num>0){ + if(num>=1000){ + for(z=0;z=500){ + if(num>=900){ + num=num%900; + s+='C'; + s+='M'; + + } + else{ + num=num%500; + s+='D'; + + } + + } + else if(num>=100){ + if(num>=400){ + num=num%400; + s+='C'; + s+='D'; + + } + else{ + + for(z=0;z=50){ + if(num>=90){ + num=num%90; + s+='X'; + s+='C'; + + } + else{ + for(z=0;z=10){ + if(num>=40){ + num=num%40; + s+='X'; + s+='L'; + + } + else{ + + for(z=0;z=5){ + if(num==9){ + s+='I'; + s+='X'; + num=0; + } + else{ + num=num%5; + s+='V'; + + } + } + else{ + if(num==4){ + s+='I'; + s+='V'; + num=0; + } + else{ + for(z=0;z