Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- my $many_first = {};
- my $many_medalist = {};
- my $worst = {};
- while (<>) {
- chomp;
- my ($name, undef, $grade) = split ',';
- ++$many_first->{$name} if $grade == 1;
- ++$many_medalist->{$name} if $grade <= 3;
- $worst->{$name} += $grade;
- }
- my $many_first_list = [];
- push @$many_first_list, [$_, $many_first->{$_}] for keys %$many_first;
- print "$_\n" for map {$_->[0]} (sort {$b->[1] <=> $a->[1]} @$many_first_list)[0, 1];
- my $many_medalist_list = [];
- push @$many_medalist_list, [$_, $many_medalist->{$_}] for keys %$many_medalist;
- print "$_\n" for map {$_->[0]} (sort {$b->[1] <=> $a->[1]} @$many_medalist_list)[0];
- my $worst_list = [];
- push @$worst_list, [$_, $worst->{$_}] for keys %$worst;
- print "$_\n" for map {$_->[0]} (sort {$b->[1] <=> $a->[1]} @$worst_list)[0];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement