- 论坛徽章:
- 1
|
回复 6# kk861123
我写的,差距怎么那么大呢,貌似脑子里没有一点数据结构的用法。。。。。。。。。学习中- open FILE, "<test.data" or die "cannot open test.data";
- my @lines = <FILE>;
- close FILE;
- for my $line (@lines)
- {
- chomp $line;
- my @nums = split ' ', $line;
- my $sign = 0;
- for my $collection (@collections)
- {
- for my $num (@nums)
- {
- if (grep /^$num$/, @$collection)
- {
- $sign = 1;
- last;
- }
- }
- if ($sign == 1)
- {
- push @$collection, grep {
- my $num = $_;
- !grep /^$num$/, @$collection;
- } @nums;
- last;
- }
- }
- if ($sign == 0)
- {
- push @collections, \@nums;
- }
- }
- for (@collections)
- {
- print join " ", sort @$_;
- print "\n";
- }
复制代码 |
|