Advertisement
Guest User

Untitled

a guest
Jun 24th, 2014
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.40 KB | None | 0 0
  1. package;
  2.  
  3. // Un élève = un nom, un prénom et une liste de notes (ils n'ont pas de vies !)
  4. typedef Student = { name:String, firstname:String, notes:Array<Int> };
  5.  
  6. class ExoLundi1 {
  7.   public static function main() {
  8.     // Nombre d'élèves voulus
  9.     var n = Std.parseInt(Sys.stdin().readLine());
  10.  
  11.     // La liste des élèves
  12.     var students = new Array<Student>();
  13.  
  14.     // Les noms possibles
  15.     var names = [
  16.       "Martin", "Bernard", "Thomas", "Petit", "Robert",
  17.       "Richard", "Durand", "Dubois", "Moreau", "Laurent",
  18.       "Simon", "Michel", "Lefebvre", "Leroy", "Roux",
  19.       "David", "Bertrand", "Morel", "Fournier", "Girard",
  20.       "Bonnet", "Dupont", "Lambert", "Fontaine", "Rousseau",
  21.       "Vincent", "Muller", "Lefevre", "Faure", "Andre"
  22.     ];
  23.  
  24.     // Les prénoms qui seront générés
  25.     var firstname_part1 = [
  26.       "Ni", "Ya", "Seba", "Si", "Mae", "Ro", "Isa", "Ce", "Ju",
  27.       "Vic", "Be", "Chri", "Bea", "Elo", "A", "Hu"
  28.     ];
  29.  
  30.     var firstname_part2 = [
  31.       "colas", "nnick", "stien", "mon", "va", "main", "belle", "dric", "lia",
  32.       "tor", "noit", "stophe", "trice", "die", "nais", "go",
  33.       "ger", "lie", "ole"
  34.     ];
  35.  
  36.     // Génération de 1000 élèves extraordinaires
  37.     var exists:Bool;
  38.     var name:String;
  39.     var firstname:String;
  40.  
  41.     for (i in 0 ... n) {
  42.       do {
  43.         exists    = false;
  44.         name      = rand_array(names).toUpperCase();
  45.         firstname = rand_array(firstname_part1) + rand_array(firstname_part2);
  46.  
  47.         for (student in students) {
  48.           if (name == student.name && firstname == student.firstname) {
  49.             exists = true;
  50.             break;
  51.           }
  52.         }
  53.       } while (exists);
  54.  
  55.       students.push({
  56.         name:      name,
  57.         firstname: firstname,
  58.         notes:     [ for (j in 0 ... 5) rand(0, 20) ]
  59.       });
  60.     }
  61.  
  62.     // Affichage des élèves
  63.     for (student in students) {
  64.       Sys.println('${student.name}, ${student.firstname} ${student.notes.join(" ")}');
  65.     }
  66.  
  67.     // Petite pause
  68.     Sys.stdin().readLine();
  69.   }
  70.  
  71.   // Génération d'un nombre [ min ; max ]
  72.   public static inline function rand(min:Int, max:Int) {
  73.     return Math.floor(Math.random() * (max - min + 1)) + min;
  74.   }
  75.  
  76.   // Récupération d'une valeur aléatoire dans une liste
  77.   public static inline function rand_array(array:Array<String>) {
  78.     return array[rand(0, array.length - 1)];
  79.   }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement