Created
December 2, 2016 11:10
-
-
Save tomcha/76f9f18dfcbeb7d5be1f9fcb1f6f51ad to your computer and use it in GitHub Desktop.
Perl入学式 #3 復習問題
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Data::Dumper; | |
my $prof1 = { | |
name => 'tomcha_', | |
favorite_foods => [ | |
'衣笠丼', | |
'寿司', | |
'お好み焼き', | |
], | |
}; | |
my $prof2 = { | |
name => 'satou', | |
favorite_foods => [ | |
'ラーメン', | |
'酢豚', | |
'寿司', | |
], | |
}; | |
my $prof3 = { | |
name => 'suzuki', | |
favorite_foods => [ | |
'寿司', | |
'天ぷら', | |
'衣笠丼', | |
], | |
}; | |
my @profiles = make_prof_array($prof1, $prof2, $prof3); | |
my %ranking; | |
for my $prof (@profiles){ | |
for my $e (@{$prof->{favorite_foods}}){ | |
$ranking{$e} += 1; | |
} | |
} | |
my @rank = reverse(sort(values(%ranking))); | |
my @keys = keys(%ranking); | |
for my $rank (@rank){ | |
for my $key (@keys){ | |
if ($ranking{$key} == $rank){ | |
print "$key : $ranking{$key} 票\n"; | |
$ranking{$key} = -1; | |
} | |
} | |
} | |
sub make_prof_array { | |
my @profs = @_; | |
return @profs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment