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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/* 789 - seven hundred and eighty nine */
/*思路:这人题思路很简单但是用c++程序实现起来比较繁琐,看了答案才知道 可以把 switch(){case}可以改成数组。哎。效率就是不行呀~!
如 char *a[]={"","one","two".........}*/
#include <iostream>
#include <string>
using
namespace
std;
char
*Num_to_en(
int
num)
{
switch
(num)
{
case
1:
return
"one"
;
break
;
case
2:
return
"tow"
;
break
;
case
3:
return
"three"
;
break
;
case
4:
return
"four"
;
break
;
case
5:
return
"five"
;
break
;
case
6:
return
"six"
;
break
;
case
7:
return
"seven"
;
break
;
case
8:
return
"eight"
;
break
;
case
9:
return
"nine"
;
break
;
default
:
cout<<
"error"
<<endl;
break
;
}
}
char
*ShiWei(
int
num)
{
if
(num<=20)
{
switch
(num)
{
case
10:
return
"ten"
;
break
;
case
11:
return
"elven"
;
break
;
case
12:
return
"twelve"
;
break
;
case
13:
return
"thirteen"
;
break
;
case
14:
return
"fourteen"
;
break
;
case
15:
return
"fifteen"
;
break
;
case
16:
return
"sixteen"
;
break
;
case
17:
return
"seventeen"
;
break
;
case
18:
return
"eighteen"
;
break
;
case
19:
return
"nineteen"
;
break
;
case
20:
return
"twenty"
;
break
;
}
}
else
{
int
s=num/10;
int
g=num%10;
switch
(s)
{
case
2:
return
"twenty"
;
break
;
case
3:
return
"thirty"
;
break
;
case
4:
return
"forty"
;
break
;
case
5:
return
"fifty"
;
break
;
case
6:
return
"sixty"
;
break
;
case
7:
return
"seventy"
;
break
;
case
8:
return
"eighty"
;
break
;
case
9:
return
"ninety"
;
break
;
case
0:
return
" "
;
}
}
}
int
main()
{
cout<<
"请输入一个三位整数"
<<endl;
int
a1;
cin>>a1;
int
bw=a1/100;
int
sw=a1%100;
int
sw1=a1%100/10;
int
gw=a1%10;
if
(sw1==0&&gw!=0) cout<<Num_to_en(bw)<<
" hundred and "
<<Num_to_en(gw)<<endl;
else
if
(sw==0&&gw==0) cout<<Num_to_en(bw)<<
" hundred"
<<endl;
else
if
(sw<21)cout<<Num_to_en(bw)<<
" hundred and "
<<ShiWei(sw)<<endl;
else
cout<<Num_to_en(bw)<<
" hundred and "
<<ShiWei(sw)<<
" "
<<Num_to_en(gw)<<endl;
return
0;
}
|