POJ 算法练习题 其一

#! usr/bin/perl
use strict;
use warnings;
use POSIX;
use 5.010;

sub calc_prog {
    my @num_of_animals;
    # my $alert_input;
    # my $num_of_feet;
    for (@_) {
        if ($_%2 != 0){
            push @num_of_animals, (0,0);
        }
        else {
            push @num_of_animals, (ceil($_/4));
            push @num_of_animals, $_/2;
        }
    }
    @num_of_animals;
}

my @number_input;
my @number_output;
print "Please input the number of feet!\n";
@number_input = ();
@number_output = calc_prog(@number_input);
my $flag;
for ($flag = 0; $flag < @number_output; $flag++) {
    if ($flag%2 == 0){
        print "$number_output[$flag] ";
    }
    else {
        print "$number_output[$flag]\n";
    }
}
    
    
# Lines_in

# my $number_input;
# my @number_output;
# print "Please input the number of feet!\n";
# my $flag;

# while ($number_input = ()) {
    # @number_output = calc_prog($number_input);
    # for ($flag = 0; $flag < @number_output; $flag++) {
        # if ($flag%2 == 0){
            # print "$number_output[$flag] ";
        # }
        # else {
            # print "$number_output[$flag]\n";
        # }
    # }
# }

你可能感兴趣的:(POJ 算法练习题 其一)