Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. void toromai(char inp[],char outp[]) /* Arab számot alakít római számmá */
  2. {
  3.     int a,n=0;
  4.     char *romai;
  5.     char egyesek[][10]  = {"I","II","III","IV","V","VI","VII","VIII","IX"};
  6.     char tizesek[][10]  = {"X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
  7.     char szazasok[][10] = {"C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
  8.     char ezresek[][4]   = {"M","MM","MMM"};
  9.    
  10.     n = strlen(inp);
  11.     a = atoi(inp);
  12.     romai=(char*)calloc(4*n,sizeof(char*));
  13.     if(1<=a && a<4000)
  14.     {
  15.         if(n==4)
  16.         {
  17.             strcat(romai,ezresek[(a/1000)-1]);
  18.             if(a%1000!=0)
  19.             {
  20.                 a%=1000;
  21.                 if(9<a%1000 && a%1000<100) n--;
  22.                 if(1<=a%1000 && a%1000<10) n-=2;
  23.                 n--;
  24.             }
  25.             else {
  26.                 strcpy(outp,romai);
  27.             }
  28.         }
  29.         if(n==3)
  30.         {
  31.             strcat(romai,szazasok[(a/100)-1]);
  32.             if(a%100!=0)
  33.             {
  34.                 a%=100;
  35.                 if(1<=a%100 && a%100<10) n--;
  36.                 n--;
  37.             }
  38.             else {
  39.                 strcpy(outp,romai);
  40.             }
  41.         }
  42.         if(n==2)
  43.         {
  44.             strcat(romai,tizesek[(a/10)-1]);
  45.             if(a%10!=0)
  46.             {
  47.                 a%=10;
  48.                 n--;
  49.             }
  50.             else {
  51.                 strcpy(outp,romai);
  52.             }
  53.         }
  54.         if(n==1) strcat(romai,egyesek[a-1]);
  55.         else {
  56.                 strcpy(outp,romai);
  57.         }
  58.     }
  59.     else {
  60.         strcpy(outp,"#ERTEK!");
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement