Skip to content

Instantly share code, notes, and snippets.

@zaneli
Last active December 20, 2015 01:18
Show Gist options
  • Save zaneli/6047676 to your computer and use it in GitHub Desktop.
Save zaneli/6047676 to your computer and use it in GitHub Desktop.
Perl 入学式 #2 補講用
#!/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";
}
}
#!/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;
#!/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";
}
#!/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