SHARE
TWEET

algos_uto.pl

teuk Aug 11th, 2019 8 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [17:35:03:teuk@teuk:~/uto] ./algos_uto.pl 1
  2. Liste A = 2,5,1,7,3,8,2,4,9,0,10
  3. Moyenne : 4.63636363636364
  4. [17:35:36:teuk@teuk:~/uto] ./algos_uto.pl 2
  5. Liste A = 2,5,1,7,3,8,2,4,9,0,10
  6. Nombre minimum dans A : 0
  7. [17:35:39:teuk@teuk:~/uto] ./algos_uto.pl 3
  8. Liste A = 2,5,1,7,3,8,2,4,9,0,10
  9. 0,1,2,2,3,4,5,7,8,9,10Liste B (A du plus petit au plus grand) : 1
  10. [17:35:43:teuk@teuk:~/uto] cat algos_uto.pl
  11. #!/usr/bin/perl
  12.  
  13. use strict;
  14. use warnings;
  15. use diagnostics;
  16. use File::Basename;
  17. use Switch;
  18. use List::Util qw( min max );
  19.  
  20. unless (defined($ARGV[0]) && ($ARGV[0] =~ /^[1-3]$/)) {
  21.         print STDERR "Usage: " . basename($0) . " 1\n";
  22.         print STDERR "=> moyenne des ents de A\n";
  23.         print STDERR "Usage: " . basename($0) . " 2\n";
  24.         print STDERR "=> renvoie toujours le plus petit des ents de A.\n";
  25.         print STDERR "Usage: " . basename($0) . " 3\n";
  26.         print STDERR "=> renvoie une liste B, contenant les ents de A du plus petit au plus grand.\n";
  27.         exit 1;
  28. }
  29.  
  30. my @A = (2,5,1,7,3,8,2,4,9,0,10);
  31. print "Liste A = " . join(",",@A) . "\n";
  32. switch($ARGV[0]) {
  33.         case "1" {
  34.                 my $sum = 0;
  35.                 for (my $i=0;$i<=$#A;$i++) { $sum+=$A[$i]; }
  36.                 print "Moyenne : " . ($sum / ($#A + 1)) . "\n";
  37.         }
  38.         case "2" {
  39.                 print "Nombre minimum dans A : " . min(@A) . "\n";
  40.         }
  41.         case "3" {
  42.                 print "Liste B (A du plus petit au plus grand) : " . print(join(",",sort { $a <=> $b } @A)) . "\n";
  43.         }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top