Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<conio.h>
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- char a[10][10]={{" khong "},{" mot "},{" hai "},{" ba "},{" bon "},{" nam "},{" sau "},{" bay "},{" tam "},{" chin "}};
- char text[1000],t[1000],cum3[100],s[1000];
- int doc_so_cum3(int n, int k)
- {
- int i=0;
- if (n==0) return 0;
- if (k!=0 || n/100!=0)
- {
- strcpy(cum3,a[n/100]);
- strcat(cum3," tram ");
- i++;
- }
- n=n%100;
- if (n==0) return 1;
- if (n/10==0)
- {
- if (n%10!=0)
- if (k!=0 || i>0) strcat(cum3," le ");
- strcat(cum3,a[n%10]);
- }
- else if (n/10==1)
- {
- strcat(cum3," muoi ");
- if (n%10!=0)
- {
- if (n%10==5) strcat(cum3," lam ");
- else strcat(cum3,a[n%10]);
- }
- }
- else
- {
- strcat(cum3,a[n/10]);
- strcat(cum3," muoi ");
- if (n%10!=0)
- {
- if (n%10==5) strcat(cum3," lam ");
- else strcat(cum3,a[n%10]);
- }
- }
- return 1;
- }
- void doc(char s[1000])
- {
- int n,i,j,dem,k=0,m,x;
- n=strlen(s);
- for (;s[j]=='0';)
- {
- n--;
- j++;
- }
- for (;n>0;n-=3)
- {
- dem=0;
- char t[3]={0,0,0};
- i=j;
- if (k==0)
- {
- if (n%3==0) m=2+j;
- else m=n%3-1+j;
- }
- else m=i+2;
- for (;i<=m;i++)
- t[dem++]=s[i];
- x=doc_so_cum3(atoi(t),k);
- if (x==1) strcat(text,cum3);
- if (n/9!=0 && (n%9==1 || n%9==2 || n%9==3)) strcat(text," ty ");
- else if (x==1 && (n%9==4 || n%9==5 || n%9==6)) strcat(text," nghin ");
- else if (x==1 && (n%9==7 || n%9==8 || n%9==0)) strcat(text," trieu ");
- j=i;
- k++;
- }
- }
- int main()
- {
- int i;
- printf("Nhap vao so can doc: ");
- gets(s);
- doc(s);
- printf("\nSo %s doc la: ",s);
- for (i=0;i<=strlen(text);i++)
- if (text[i]==' ' && text[i-1]!=' ' || text[i]!=' ')
- printf("%c",text[i]);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment