cptfrosty322

GeneratorVariants

Mar 4th, 2022
1,385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace GeneratorVariants
  5. {
  6.  
  7.     class Program
  8.     {
  9.         public static List<string> numTasks = new List<string>
  10.         {
  11.             "120",
  12.             "121",
  13.             "122",
  14.             "123",
  15.             "124",
  16.             "125",
  17.             "126",
  18.             "127",
  19.             "128",
  20.             "129а",
  21.             "120б",
  22.             "120в",
  23.             "120г",
  24.             "120д",
  25.             "120е",
  26.             "120ж",
  27.             "120з",
  28.             "120и",
  29.             "120к",
  30.             "120л",
  31.             "120м",
  32.             "120н",
  33.             "120о",
  34.             "130а",
  35.             "130б",
  36.             "130в",
  37.             "130г",
  38.             "130д",
  39.             "130е",
  40.             "130ж",
  41.             "130з",
  42.             "130и",
  43.             "130к",
  44.             "130л",
  45.             "130м",
  46.             "130н",
  47.             "130о",
  48.             "130п",
  49.             "130р",
  50.             "131",
  51.             "132",
  52.             "133",
  53.             "134",
  54.             "135"
  55.         };
  56.  
  57.         public static int countTasks = 5;
  58.         public static int countVariants = 30;
  59.         public static int[] indexTasks;
  60.         static void Main(string[] args)
  61.         {
  62.             for (int i = 0; i < countVariants; i++) {
  63.                 indexTasks = new int[countTasks];
  64.                 Console.WriteLine($"Вариант {i+1}:");
  65.                 for (int j = 0; j < indexTasks.Length; j++)
  66.                 {
  67.                     indexTasks[j] = ChoiseNum();
  68.                     if (j == indexTasks.Length - 1)
  69.                         Console.Write($"{numTasks[indexTasks[j]]}");
  70.                     else
  71.                         Console.Write($"{numTasks[indexTasks[j]]}, ");
  72.  
  73.                    
  74.                 }
  75.                 Console.WriteLine();
  76.             }
  77.         }
  78.  
  79.         static int ChoiseNum()
  80.         {
  81.             bool isAdd = false;
  82.             int num = 0;
  83.             Random rnd = new Random();
  84.             do
  85.             {
  86.                 num = rnd.Next(0, numTasks.Count);
  87.                 isAdd = CheckAvailability(num);
  88.             } while (!isAdd);
  89.  
  90.             return num;
  91.         }
  92.  
  93.         static bool CheckAvailability(int index)
  94.         {
  95.             bool result = true;
  96.             for(int i = 0; i < indexTasks.Length; i++)
  97.             {
  98.                 if(index == indexTasks[i])
  99.                 {
  100.                     result = false;
  101.                     break;
  102.                 }
  103.             }
  104.  
  105.             return result;
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment