• 博客访问： 240039
• 博文数量： 54
• 博客积分： 35
• 博客等级： 民兵
• 技术积分： 729
• 用 户 组： 普通用户
• 注册时间： 2012-02-09 10:35

2014年（37）

2013年（17）

2013-12-27 17:45:47

0

1
12
123
1234
12345
123456
1234567
12345678
123456789
1234567890

1
10
100
1000
10000
100000
1000000
10000000
100000000
1000000000

zero

one
twelve
one hundred and twenty-three
one thousand,two hundred and thirty-four
twelve thousand,three hundred and forty-five
one hundred and twenty-three thousand,four hundred and fifty-six
one million,two hundred and thirty-four thousand,five hundred and sixty-seven
twelve million,three hundred and forty-five thousand,six hundred and seventy-eight
one hundred and twenty-three million,four hundred and fifty-six thousand,seven hundred and eighty-nine
one billion,two hundred and thirty-four million,five hundred and sixty-seven thousand,eight hundred and ninety

one
ten
one hundred
one thousand
ten thousand
one hundred thousand
one million
ten million
one hundred million
one billion

1. #!/bin/awk -f

2. BEGIN {
3.         FS=""
4.         a="zero"
5.         a="one"
6.         a="two"
7.         a="three"
8.         a="four"
9.         a="five"
10.         a="six"
11.         a="seven"
12.         a="eight"
13.         a="nine"
14.         a="ten"
15.         a="eleven"
16.         a="twelve"
17.         a="thirteen"
18.         a="fourteen"
19.         a="fifteen"
20.         a="sixteen"
21.         a="seventeen"
22.         a="eighteen"
23.         a="nineteen"
24.         a="twenty"
25.         a="thirty"
26.         a="forty"
27.         a="fifty"
28.         a="sixty"
29.         a="seventy"
30.         a="eighty"
31.         a="ninety"
32. }

33. {
34.         for (i=1;i<=NF;i++) {
35.                 t=NF-i+1
36.                 k=0
37.                 if (!\$i&&i>1) continue
38.                 if (!(t%3)) {
39.                         printf a[\$i]" hundred"
40.                         if (!\$(i+1)) {
41.                                 if (\$(i+2)) printf " and "a[\$(i+2)]
42.                                 i+=2
43.                         } else printf " and "
44.                 } else if (t%3==2) {
45.                         if (\$i=="1") {
46.                                 printf a[\$i\$(i+1)]
47.                         } else {
48.                                 if (\$(i+1)) printf a[\$i*10]"-"a[\$(i+1)];else printf a[\$i*10]
49.                         }
50.                         i++
51.                 } else printf a[\$i]
52.                 t=NF-i+1
53.                 if (t==4) printf " thousand"
54.                 if (t==7) printf " million"
55.                 if (t==10) printf " billion"
56.                 if (t%3==1) {
57.                         for (j=i+1;j<=NF;j++) if (\$j) k=1
58.                         if (k) printf ","
59.                 }
60.         }
61.         print ""
62. }

0