Jump to content

Home

Programming discussion


ET Warrior

Recommended Posts

Bah to Java.

Perl solution:

[spoiler][size=1]open $movie_database, "<", "movie.dat";

while (<$movie_database>) {
 next unless /\$(\d+)\s+\$(\d+)/;
 $this_gross=$1+$2;
 $this_movie=unpack('A*',substr($_,8,40));
 if ($this_gross>$top3_gross) {
   if ($this_gross>$top2_gross) {
       if ($this_gross>$top1_gross) {
           $top3_movie=$top2_movie;
           $top3_gross=$top2_gross;
           $top2_movie=$top1_movie;
           $top2_gross=$top1_gross;
           $top1_movie=$this_movie;
           $top1_gross=$this_gross;
       }
       else {
           $top3_movie=$top2_movie;
           $top3_gross=$top2_gross;
           $top2_movie=$this_movie;
           $top2_gross=$this_gross;
       }
   }
   else {
      $top3_movie=$this_movie;
      $top3_gross=$this_gross;
   }
 }
}
close $movie_database;
printf "Top 3 Movies:\n%s \$%d\n%s \$%d\n%s \$%d",
  $top1_movie, $top1_gross,
  $top2_movie, $top2_gross,
  $top3_movie, $top3_gross;
[/size][/spoiler]

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...