-
Notifications
You must be signed in to change notification settings - Fork 0
/
17.c
89 lines (86 loc) · 1.44 KB
/
17.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
char digits[20][10] = {
"",
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
"Eleven",
"Twelve",
"Thirteen",
"Fourteen",
"Fifteen",
"Sixteen",
"Seventeen",
"Eighteen",
"Nineteen"
};
char tens[11][10] = {
"",
"",
"Twenty",
"Thirty",
"Forty",
"Fifty",
"Sixty",
"Seventy",
"Eighty",
"Ninety"
};
void word(int num) {
if (num / 100)
printf("%s Hundred ", digits[num / 100]);
if ((num % 100) < 20 && (num % 100) > 0)
printf("%s ", digits[num % 100]);
else if ((num / 10) % 10) {
printf("%s ", tens[(num / 10) % 10]);
if (num % 10)
printf("%s ", digits[num % 10]);
}
}
int main() {
int t;
scanf("%d", & t);
while (t--) {
long long int num;
scanf("%lld", & num);
int tn = num / 1000000000000;
int bn = (num / 1000000000) % 1000;
int mn = (num / 1000000) % 1000;
int th = (num / 1000) % 1000;
int hd = num % 1000;
//printf("%d %d %d %d %d\n", tn, bn, mn, th, hd);
if ((tn + bn + mn + th + hd) == 0)
printf("Zero");
if (tn) {
word(tn);
printf("Trillion ");
}
if (bn) {
word(bn);
printf("Billion ");
}
if (mn) {
word(mn);
printf("Million ");
}
if (th) {
word(th);
printf("Thousand ");
}
if (hd) {
word(hd);
}
printf("\n");
}
return 0;
}