Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6.  
  7. void egyes(int n)
  8. {
  9.     if(n == 9) cout << "IX";
  10.     else if(n == 4) cout << "IV";
  11.     else
  12.     {
  13.         if(n >= 5) cout << "V";
  14.         for(int i=1; i <= n % 5; i ++)
  15.         {
  16.             cout << "I";
  17.         }
  18.     }
  19. }
  20.  
  21. void kettes(int n)
  22. {
  23.     for(int i=1; i <= n/10; i++)
  24.     {
  25.         cout << "X";
  26.     }
  27.     egyes(n % 10);
  28. }
  29.  
  30. void harmas(int n)
  31. {
  32.     for(int i=1; i <= n/100; i++)
  33.     {
  34.         cout << "C";
  35.     }
  36.     n %= 100;
  37.     if(n > 89)
  38.     {
  39.         cout << "XC";
  40.         egyes(n - 90);
  41.     }
  42.     else if(n >= 50)
  43.     {
  44.         cout << "L";
  45.         kettes(n - 50);
  46.     }
  47.     else if(n > 39)
  48.     {
  49.         cout << "XL";
  50.         egyes(n - 40);
  51.     }
  52.     else
  53.     {
  54.         kettes(n);
  55.     }
  56. }
  57.  
  58. int main()
  59. {
  60.     int n;
  61.     setlocale(LC_ALL, "HUN");
  62.  
  63.     while(true)
  64.     {
  65.         cout << "\n\nKérek egy számot: ";
  66.         cin >> n;
  67.  
  68.         if(n > 1001 || !isdigit(n))
  69.         {
  70.             cout << "Hibás a bemenet.";
  71.             return 0;
  72.         }
  73.  
  74.         if(n == 1000)
  75.         {
  76.             cout << "M";
  77.         }
  78.         else
  79.         {
  80.             if(n > 899)
  81.             {
  82.                 cout << "CM";
  83.                 n -= 900;
  84.             }
  85.             else if(n >= 500)
  86.             {
  87.                 cout << "D";
  88.                 n -= 500;
  89.             }
  90.             else if(n > 399)
  91.             {
  92.                 cout << "CD";
  93.                 n -= 400;
  94.             }
  95.             harmas(n);
  96.         }
  97.     }
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement