rodrwan

Civic Dill Mix

May 3rd, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define MAXS 5000
  6.  
  7. using namespace std;
  8.  
  9. void roman_num(int);
  10. int num_roman(char numero_R[500]);
  11.  
  12. int main()
  13. {
  14.    int cases;
  15.    char roman[MAXS];
  16.    int suma=0;
  17.    int I = 0;
  18.    int cas = 1;
  19.    
  20.    while (cin >> cases,cases != 0)
  21.    {
  22.        for (int i = 0; i < cases; i++)
  23.        {
  24.             cin >> roman;
  25.             suma += num_roman(roman);
  26.        }
  27.        cout << "Case ";
  28.        roman_num(cas);
  29.        cout << ": ";
  30.        roman_num(suma);
  31.        cout << endl;
  32.        cas++;
  33.        suma = 0;
  34.    }   
  35. }
  36.  
  37. int num_roman(char numero_R[500])
  38. {
  39.   int numero_A[500];
  40.   int suma = 0,ix;
  41.  
  42.   for(ix = 0;ix < 500;ix++)
  43.     numero_A[ix] = 0;
  44.  
  45.   for (ix = 0;ix < strlen(numero_R);ix++)
  46.   {
  47.     switch(numero_R[ix])
  48.     {
  49.       case 'I': numero_A[ix] = 1; break;
  50.       case 'V': numero_A[ix] = 5; break;
  51.       case 'X': numero_A[ix] = 10; break;
  52.       case 'L': numero_A[ix] = 50; break;
  53.       case 'C': numero_A[ix] = 100; break;
  54.       case 'D': numero_A[ix] = 500; break;
  55.       case 'M': numero_A[ix] = 1000; break;
  56.       default:
  57.       {
  58.         return (-1); break;
  59.       }
  60.     }
  61.   }
  62.  
  63.   for(ix = 0;ix < strlen(numero_R);ix++)
  64.   {
  65.     if(numero_A[ix] < numero_A[ix+1])
  66.       suma -= numero_A[ix];
  67.     else
  68.       suma += numero_A[ix];
  69.   }
  70.  
  71.   return (suma);
  72. }
  73.  
  74. void roman_num(int num)
  75. {
  76.     int entero,res;
  77.     /* Dividimos por 1000 */
  78.     entero = num/1000;
  79.     res = num%1000;
  80.     switch( entero )
  81.     {
  82.         case 1: printf( "M" ); break;
  83.         case 2: printf( "MM" ); break;
  84.         case 3: printf( "MMM" ); break;
  85.         case 4: printf( "MMMM" ); break;
  86.         case 5: printf( "MMMMM" ); break;
  87.     }
  88.     /* Dividimos por 100 */
  89.     entero = res/100;
  90.     res = res%100;
  91.     switch( entero )
  92.     {
  93.         case 1: printf( "C" ); break;
  94.         case 2: printf( "CC" ); break;
  95.         case 3: printf( "CCC" ); break;
  96.         case 4: printf( "CD" ); break;
  97.         case 5: printf( "D" ); break;
  98.         case 6: printf( "DC" ); break;
  99.         case 7: printf( "DCC" ); break;
  100.         case 8: printf( "DCCC" ); break;
  101.         case 9: printf( "CM" ); break;
  102.     }
  103.     /*Dividimos por 10 */
  104.     entero = res/10;
  105.     res=res%10;
  106.     switch( entero )
  107.     {
  108.         case 1: printf( "X" ); break;
  109.         case 2: printf( "XX" ); break;
  110.         case 3: printf( "XXX" ); break;
  111.         case 4: printf( "XL" ); break;
  112.         case 5: printf( "L" ); break;
  113.         case 6: printf( "LX" ); break;
  114.         case 7: printf( "LXX" ); break;
  115.         case 8: printf( "LXXX" ); break;
  116.         case 9: printf( "XC" ); break;
  117.     }
  118.     switch( res )
  119.     {
  120.         case 1: printf( "I" ); break;
  121.         case 2: printf( "II" ); break;
  122.         case 3: printf( "III" ); break;
  123.         case 4: printf( "IV" ); break;
  124.         case 5: printf( "V" ); break;
  125.         case 6: printf( "VI" ); break;
  126.         case 7: printf( "VII" ); break;
  127.         case 8: printf( "VIII" ); break;
  128.         case 9: printf( "IX" ); break;
  129.      } 
  130. }
Advertisement
Add Comment
Please, Sign In to add comment