Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- // Un élève = un nom, un prénom et une liste de notes (ils n'ont pas de vies !)
- typedef Student = { name:String, firstname:String, notes:Array<Int> };
- class ExoLundi1 {
- public static function main() {
- // La liste des élèves
- var students = new Array<Student>();
- // Les noms possibles
- var names = [
- "Martin", "Bernard", "Thomas", "Petit", "Robert",
- "Richard", "Durand", "Dubois", "Moreau", "Laurent",
- "Simon", "Michel", "Lefebvre", "Leroy", "Roux",
- "David", "Bertrand", "Morel", "Fournier", "Girard",
- "Bonnet", "Dupont", "Lambert", "Fontaine", "Rousseau",
- "Vincent", "Muller", "Lefevre", "Faure", "Andre"
- ];
- // Les prénoms qui seront générés
- var firstname_part1 = [
- "Ni", "Ya", "Seba", "Si", "Mae", "Ro", "Isa", "Ce", "Ju",
- "Vic", "Be", "Chri", "Bea", "Elo", "A", "Hu"
- ];
- var firstname_part2 = [
- "colas", "nnick", "stien", "mon", "va", "main", "belle", "dric", "lia",
- "tor", "noit", "stophe", "trice", "die", "nais", "go",
- "ger", "lie", "ole"
- ];
- // Génération de 1000 élèves extraordinaires
- var exists:Bool;
- var name:String;
- var firstname:String;
- for (i in 0 ... 1000) {
- do {
- exists = false;
- name = rand_array(names).toUpperCase();
- firstname = rand_array(firstname_part1) + rand_array(firstname_part2);
- for (student in students) {
- if (name == student.name && firstname == student.firstname) {
- exists = true;
- break;
- }
- }
- } while (exists);
- students.push({
- name: name,
- firstname: firstname,
- notes: [ for (j in 0 ... 5) rand(0, 20) ]
- });
- }
- // Affichage des élèves
- for (student in students) {
- Sys.println('${student.name}, ${student.firstname} ${student.notes.join(" ")}');
- }
- // Petite pause
- Sys.stdin().readLine();
- }
- // Génération d'un nombre [ min ; max ]
- public static inline function rand(min:Int, max:Int) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- // Récupération d'une valeur aléatoire dans une liste
- public static inline function rand_array(array:Array<String>) {
- return array[rand(0, array.length - 1)];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement