我也手痒...
写个perl 的发出来- use strict;
- my %point = (
- "万" => 5,
- "亿" => 9
- );
- my %base = (
- "千" => 4,
- "百" => 3,
- "十" => 2
- );
- my %num = (
- "零" => 0,
- "一" => 1,
- "二" => 2,
- "三" => 3,
- "四" => 4,
- "五" => 5,
- "六" => 6,
- "七" => 7,
- "八" => 8,
- "九" => 9
- );
- my $utf8CharBit = 3;
- my @digits = ();
- my $number = "三千七百八十四万六千一百二十五";
- print getLessThanOneHundredMillionNumber("一万三千零四十五");
- # 比一亿小
- sub getLessThanOneHundredMillionNumber{
- my ($chineseNumber) = @_;
- my ($first, $second) = split "万", $chineseNumber;
- my @digits;
- my $firstDigits = getLessThanTenThousandNumber($first);
- push @digits, @$firstDigits;
- my $secondDigits = getLessThanTenThousandNumber($second);
- push @digits, @$secondDigits;
- return (sprintf "%d" x 8 . "\n", @digits) + 0;
- }
- # 比一千小
- sub getLessThanTenThousandNumber{
- my ($chineseNumber) = @_;
- my @digits;
- my $thuIndex = index $chineseNumber, "千";
- my $hunIndex = index $chineseNumber, "百";
- my $tenIndex = index $chineseNumber, "十";
- push @digits, ($thuIndex > 0) ? $num{substr $chineseNumber, 0, $thuIndex} : 0;
- push @digits, ($hunIndex > 0) ? $num{substr $chineseNumber, $hunIndex - $utf8CharBit, $utf8CharBit} : 0;
- push @digits, ($tenIndex > 0) ? $num{substr $chineseNumber, $tenIndex - $utf8CharBit, $utf8CharBit} : 0;
- push @digits, $num{substr $chineseNumber, length ($chineseNumber) - $utf8CharBit};
- #printf "%d" x 4 . "\n", @digits;
- return \@digits;
- }
复制代码 |