Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
aju
#include <stdio.h> #include <string.h> #include <stdlib.h> void func(char *num) { int len = strlen(num); if (len == 0) { fprintf(stderr, "empty string\n"); return; } if (len > 4) { fprintf(stderr, "Length more than 4 is not supported\n"); return; } char *single_digits[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; char *two_digits[] = {"", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; char *tens_multiple[] = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}; char *tens_power[] = {"hundred", "thousand"}; printf("\n%s: ", num); if (len == 1) { printf("%s\n", single_digits[*num - '0']); return; } while (*num != '\0') { if (len >= 3) { if (*num -'0' != 0) { printf("%s ", single_digits[*num - '0']); printf("%s ", tens_power[len-3]); // here len can be 3 or 4 } --len; } else { if (*num == '1') { int sum = *num - '0' + *(num + 1)- '0'; printf("%s\n", two_digits[sum]); return; } else if (*num == '2' && *(num + 1) == '0') { printf("twenty\n"); return; } else { int i = *num - '0'; printf("%s ", i? tens_multiple[i]: ""); ++num; if (*num != '0') printf("%s ", single_digits[*num - '0']); } } ++num; } } int main(void) { int i=0,l,n; char c,s[5]; scanf("%d",&n); while(n>0) { s[i]=n%10+48; n/=10; i++; } l=i; s[i]='\0'; for(i=0;i<l/2;i++) { c=s[i]; s[i]=s[l-1-i]; s[l-1-i]=c; } // printf("%s",s); func(s); return 0; }
run
|
edit
|
history
|
help
0
KMP substring search
PrintShape
begin_end.cpp
Web Browser History - DLL
10 wizards-DFS_vector
Hello World C++ - minimal
hilbert
Rectangle overlap
GCC bug #79511
Stream generalization