fuliver123

Đọc số

Nov 19th, 2015
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1. #include<conio.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5.  
  6. char a[10][10]={{" khong "},{" mot "},{" hai "},{" ba "},{" bon "},{" nam "},{" sau "},{" bay "},{" tam "},{" chin "}};
  7. char text[1000],t[1000],cum3[100],s[1000];
  8.  
  9. int doc_so_cum3(int n, int k)
  10. {
  11.     int i=0;
  12.     if (n==0) return 0;
  13.     if (k!=0 || n/100!=0)
  14.     {
  15.         strcpy(cum3,a[n/100]);
  16.         strcat(cum3," tram ");
  17.         i++;
  18.     }
  19.     n=n%100;
  20.     if (n==0) return 1;
  21.     if (n/10==0)
  22.         {
  23.             if (n%10!=0)
  24.                 if (k!=0 || i>0) strcat(cum3," le ");
  25.             strcat(cum3,a[n%10]);
  26.         }
  27.     else if (n/10==1)
  28.     {
  29.         strcat(cum3," muoi ");
  30.         if (n%10!=0)
  31.         {
  32.             if (n%10==5) strcat(cum3," lam ");
  33.             else strcat(cum3,a[n%10]);
  34.         }      
  35.     }
  36.     else
  37.     {
  38.         strcat(cum3,a[n/10]);
  39.         strcat(cum3," muoi ");
  40.         if (n%10!=0)
  41.         {
  42.             if (n%10==5) strcat(cum3," lam ");
  43.             else strcat(cum3,a[n%10]);
  44.         }          
  45.     }
  46.     return 1;
  47. }
  48.  
  49. void doc(char s[1000])
  50. {
  51.     int n,i,j,dem,k=0,m,x;
  52.     n=strlen(s);
  53.     for (;s[j]=='0';)
  54.     {
  55.         n--;
  56.         j++;
  57.     }
  58.     for (;n>0;n-=3)
  59.     {
  60.         dem=0;
  61.         char t[3]={0,0,0};
  62.         i=j;
  63.         if (k==0)
  64.         {
  65.             if (n%3==0) m=2+j;
  66.             else m=n%3-1+j;
  67.         }
  68.         else m=i+2;
  69.         for (;i<=m;i++)
  70.             t[dem++]=s[i];
  71.         x=doc_so_cum3(atoi(t),k);
  72.         if (x==1) strcat(text,cum3);
  73.         if (n/9!=0  && (n%9==1 || n%9==2 || n%9==3)) strcat(text," ty ");
  74.         else if (x==1 && (n%9==4 || n%9==5 || n%9==6)) strcat(text," nghin ");
  75.         else if (x==1 && (n%9==7 || n%9==8 || n%9==0)) strcat(text," trieu "); 
  76.         j=i;
  77.         k++;
  78.     }  
  79. }
  80.  
  81. int main()
  82. {
  83.     int i;
  84.     printf("Nhap vao so can doc: ");
  85.     gets(s);
  86.     doc(s);
  87.     printf("\nSo %s doc la: ",s);
  88.     for (i=0;i<=strlen(text);i++)
  89.         if (text[i]==' ' && text[i-1]!=' ' || text[i]!=' ')
  90.             printf("%c",text[i]);
  91.     getch();
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment