fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. /**
  6. Convert decimal number lying between 1-3999 to roman numerals
  7.  
  8. SYMBOL VALUE
  9. I 1
  10. II 2
  11. III 3
  12. IV 4
  13. V 5
  14. X 10
  15. L 50
  16. C 100
  17. D 500
  18. M 1000
  19. **/
  20. string roman(int n){
  21. string res = "";
  22.  
  23. while(n > 0) {
  24. if(n >= 1000) {
  25. res = res + "M";
  26. n -= 1000;
  27. }
  28. else if(n >= 500) {
  29. res = res + "D";
  30. n -= 500;
  31. }
  32. else if(n >= 100) {
  33. res = res + "C";
  34. n -= 100;
  35. }
  36. else if(n >= 50) {
  37. res = res + "L";
  38. n -= 50;
  39. }
  40. else if(n >= 10) {
  41. res = res + "X";
  42. n -= 10;
  43. }
  44. else if(n >= 5) {
  45. res = res + "V";
  46. n -= 5;
  47. }
  48. else {
  49. res = res + "I";
  50. n--;
  51. }
  52. }
  53. return res;
  54. }
  55.  
  56. int main() {
  57. int intNum = 0;
  58. cin >> intNum;
  59. cout << roman(intNum);
  60. return 0;
  61. }
Success #stdin #stdout 0s 5300KB
stdin
90
stdout
LXXXX