Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- namespace Arrays
- {
- class AsignacionExpo2
- {
- static void Main(string[] args)
- {
- string[] temasArray = { "1. Que es POO", "2. Diferencias Prog Est-POO", "3. Abstracción", "4. Encapsulación", "5. Herencia", "6. Polimorfismo" };
- string[] aprendicesArray = { "Juan Ceballos", "Mateo", "Marly", "Anderson", "Yuliana", "Paola", "Maria A", "Juan Zapata", "Tatiana", "Santiago", "Nicolas", "Luis Espitia", "Juan Jose", "Jaider", "Adrian" };
- int[] cantAprendTemasMax = { 2, 2, 2, 3, 3, 3 };
- string[] aprendicesTemasArray = new string[15];
- Random rand = new Random();
- bool isTemaSeleccionado;
- int aleatorioTema;
- Console.WriteLine("Cantidad de Aprendices: " + aprendicesArray.Length);
- Console.WriteLine("************************");
- // Mostrar temas
- for (int i = 0; i < temasArray.Length; i++)
- Console.WriteLine("Tema: " + temasArray[i]);
- Console.WriteLine("************************");
- // Ciclo para recorrer todos los aprendices para la asignación de temas
- for (int i = 0; i < aprendicesArray.Length; i++)
- {
- isTemaSeleccionado = false; // Variable para controlar la selección del tema a un aprendiz
- while (!isTemaSeleccionado) // Se ejecuta mientras no se haya asignado un tema a un aprendiz ya que el número aleatorio
- {
- aleatorioTema = rand.Next(0, temasArray.Length);// Se genera un número aleatorio según la cantidad de temas
- if (cantAprendTemasMax[aleatorioTema] > 0)
- {
- cantAprendTemasMax[aleatorioTema]--;
- isTemaSeleccionado = true;
- // Se concatena el tema asignado con el aprendiz en cuestión
- aprendicesTemasArray[i] = temasArray[aleatorioTema] + " - " + aprendicesArray[i];
- }
- }
- }
- Console.WriteLine("Los temas asignados son:");
- Array.Sort(aprendicesTemasArray);
- foreach (string item in aprendicesTemasArray)
- {
- Console.WriteLine(item);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment