Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.14 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use List::Util qw(max);
  5.  
  6. open my $fin, '<', 'input.txt' or die;
  7. open my $fout, '>', 'output.txt' or die;
  8.  
  9. my $col = <$fin> * 6 + 1;
  10. my @line = split / / , <$fin>;                
  11. my $row = max(@line) + 3;
  12.  
  13. for(my $i = 0; $i < $row; $i++) {
  14.     for (my $j = 0; $j < $col; $j++) {
  15.  
  16.         if ($i == 0 || $i == $row - 1) {
  17.             if ($i == $row - 1 && $j > 0) {
  18.                 print $fout '+---+-';
  19.                 $j += 5;
  20.                 next;
  21.             }
  22.             $i == $row - 1 ? print $fout '-' : print $fout '.';
  23.             next;
  24.         }
  25.  
  26.         for(my $k = 0; $k < scalar(@line); $k++) {
  27.                 if ($j == $k * 6 + 1 && $row - $line[$k] - 2 == $i) {
  28.                     print $fout '+---+';
  29.                     $j += 5;
  30.                 }
  31.                 elsif ($j == $k * 6 + 1 && $row - $line[$k] - 2 < $i) {
  32.                     print $fout '|###|';
  33.                     $j += 5;
  34.                 }
  35.             }
  36.         if($j < $col) {
  37.             print $fout '.';
  38.         }
  39.     }
  40.     print $fout "\n";
  41. }
  42. close $fin or die;
  43. close $fout or die;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement