Chinaunix首页 | 论坛 | 博客
  • 博客访问: 258129
  • 博文数量: 54
  • 博客积分: 35
  • 博客等级: 民兵
  • 技术积分: 729
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-09 10:35
文章分类

全部博文(54)

文章存档

2014年(37)

2013年(17)

分类: LINUX

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[0]="zero"
  5.         a[1]="one"
  6.         a[2]="two"
  7.         a[3]="three"
  8.         a[4]="four"
  9.         a[5]="five"
  10.         a[6]="six"
  11.         a[7]="seven"
  12.         a[8]="eight"
  13.         a[9]="nine"
  14.         a[10]="ten"
  15.         a[11]="eleven"
  16.         a[12]="twelve"
  17.         a[13]="thirteen"
  18.         a[14]="fourteen"
  19.         a[15]="fifteen"
  20.         a[16]="sixteen"
  21.         a[17]="seventeen"
  22.         a[18]="eighteen"
  23.         a[19]="nineteen"
  24.         a[20]="twenty"
  25.         a[30]="thirty"
  26.         a[40]="forty"
  27.         a[50]="fifty"
  28.         a[60]="sixty"
  29.         a[70]="seventy"
  30.         a[80]="eighty"
  31.         a[90]="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. }


阅读(1496) | 评论(0) | 转发(0) |
0

上一篇:sed打点计数法

下一篇:千分位

给主人留下些什么吧!~~