Created
July 13, 2019 04:40
-
-
Save sironekotoro/097514df7111d5d5deb0df0bdb8999e2 to your computer and use it in GitHub Desktop.
Perl入学式 2019第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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my %data = ( | |
alice => 'sushi', | |
bob => 'soba', | |
carol => 'sushi', | |
dave => 'sushi', | |
ellen => 'soba', | |
frank => 'udon', | |
); | |
# 以下のように、 $data に人物名と好きな食べ物がハッシュで | |
# 与えられています。 食べ物が何回出現したか表示してください。 | |
my %food_count = ( | |
soba => 0, | |
sushi => 0, | |
udon => 0, | |
); | |
for my $name ( keys %data ) { | |
my $food = $data{$name}; | |
$food_count{ $food }++; | |
} | |
for my $food ( keys %food_count ) { | |
print $food . "\t:\t" . $food_count{$food} . "\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment