Last active
December 20, 2015 01:18
-
-
Save zaneli/6047676 to your computer and use it in GitHub Desktop.
Perl 入学式 #2 補講用
This file contains hidden or 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; | |
for my $i (1 .. 100) { | |
my $fizz = $i % 3 == 0; | |
my $buzz = $i % 5 == 0; | |
if ($fizz && $buzz) { | |
print "FizzBuzz\n"; | |
} elsif ($fizz) { | |
print "Fizz\n"; | |
} elsif ($buzz) { | |
print "Buzz\n"; | |
} else { | |
print "$i\n"; | |
} | |
} |
This file contains hidden or 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 $answer = 10; | |
chomp(my $input = <STDIN>); | |
my $result; | |
if ($answer == $input) { | |
$result = "ok!\n"; | |
} elsif ($answer - 5 <= $input && $answer + 5 >= $input) { | |
$result = "near!\n"; | |
} elsif ($answer < $input) { | |
$result = "too big!\n"; | |
} else { | |
$result = "too small!\n"; | |
} | |
print $result; |
This file contains hidden or 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 $answer = "perl"; | |
chomp(my $input = <STDIN>); | |
if ($answer eq $input) { | |
print "OK!\n"; | |
} else { | |
print "NG!\n"; | |
} |
This file contains hidden or 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 @input_array; | |
for my $i (0 .. 2) { | |
chomp($input_array[$i] = <STDIN>); | |
} | |
my @sorted_array = sort {$a cmp $b} @input_array; | |
for my $elem (@sorted_array) { | |
print "$elem\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment