Advertisement
cd62131

statics for (name, point, grade)

Jan 21st, 2018
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.82 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. my $many_first = {};
  5. my $many_medalist = {};
  6. my $worst = {};
  7. while (<>) {
  8.   chomp;
  9.   my ($name, undef, $grade) = split ',';
  10.   ++$many_first->{$name} if $grade == 1;
  11.   ++$many_medalist->{$name} if $grade <= 3;
  12.   $worst->{$name} += $grade;
  13. }
  14. my $many_first_list = [];
  15. push @$many_first_list, [$_, $many_first->{$_}] for keys %$many_first;
  16. print "$_\n" for map {$_->[0]} (sort {$b->[1] <=> $a->[1]} @$many_first_list)[0, 1];
  17. my $many_medalist_list = [];
  18. push @$many_medalist_list, [$_, $many_medalist->{$_}] for keys %$many_medalist;
  19. print "$_\n" for map {$_->[0]} (sort {$b->[1] <=> $a->[1]} @$many_medalist_list)[0];
  20. my $worst_list = [];
  21. push @$worst_list, [$_, $worst->{$_}] for keys %$worst;
  22. print "$_\n" for map {$_->[0]} (sort {$b->[1] <=> $a->[1]} @$worst_list)[0];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement