标题: [原创代码] 【练习-042】将文本数值按尾数分类 [打印本页]
作者: sxw 时间: 2011-10-9 15:34 标题: 【练习-042】将文本数值按尾数分类
- #!/usr/bin/perl
- use strict;
- use warnings;
-
- my @num;
- push @num,split while(<DATA>);
- for my $z(0..9) {
- print "$z ";
- for (@num) {
- print "$_ " if /$z$/;
- }
- print "\n";
- }
- __DATA__
- 530 862 477 448
- 407 68 191 157 929
- 76 866 730 445 665
- 591 99 285 868
- 352 64 196 755 220
- 922 245 966 294 118
- 839 757 564 701 391
- 629 794 33 253
- 110 349 604 962 868
- 846 20 637 11 782
- 233 10 23 593 51
复制代码
作者: sxw 时间: 2011-10-9 15:34
加入数值排序:- #!/usr/bin/perl
- use strict;
- use warnings;
-
- my @num;
- push @num,split while(<DATA>);
- for my $z(0..9) {
- print "$z ";
- for (sort {$a <=> $b} @num) {
- print "$_ " if /$z$/;
- }
- print "\n";
- }
- __DATA__
- 530 862 477 448
- 407 68 191 157 929
- 76 866 730 445 665
- 591 99 285 868
- 352 64 196 755 220
- 922 245 966 294 118
- 839 757 564 701 391
- 629 794 33 253
- 110 349 604 962 868
- 846 20 637 11 782
- 233 10 23 593 51
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |