Skip to content

Commit

Permalink
Merge pull request #92 from SonuKushwaha-hub/patch-1
Browse files Browse the repository at this point in the history
Create Integer to Roman
  • Loading branch information
Yaswanth14 authored Oct 31, 2022
2 parents a554fdb + fd3f780 commit 08091bd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Leetcode/Integer to Roman
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <string>
using namespace std;

string intToRoman(int num)
{
string ones[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
string tens[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
string hrns[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
string ths[] = {"", "M", "MM", "MMM"};

return ths[num / 1000] + hrns[(num % 1000) / 100] + tens[(num % 100) / 10] + ones[num % 10];
}
int main()
{
int num = 24;
cout << "Enter the number: ";
cin >> num;
cout << intToRoman(num) << endl;
}

0 comments on commit 08091bd

Please sign in to comment.