Advertisement
nevenailievaa

2201682020-Domashno1

Oct 9th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. namespace HomeWork
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     class Task_1
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             bool isExitLoop = false;
  11.             int n = 0;
  12.  
  13.             while (!isExitLoop)
  14.             {
  15.                 n = int.Parse(Console.ReadLine());
  16.  
  17.                 if (n >= 13 && n <= 25)
  18.                 {
  19.                     isExitLoop = true;
  20.                 }
  21.             }
  22.  
  23.             int[] arr = CreateArray(n);
  24.  
  25.             int[] sortedArray = arr.OrderByDescending(x => x).ToArray();
  26.  
  27.             Console.WriteLine(String.Join(" ", sortedArray));
  28.         }
  29.  
  30.         static int[] CreateArray(int n)
  31.         {
  32.             int[] result = new int[n];
  33.  
  34.             for (int i = 0; i < result.Length; i++)
  35.             {
  36.                 result[i] = int.Parse(Console.ReadLine());
  37.             }
  38.  
  39.             return result;
  40.         }
  41.  
  42.         static int MaxElement(int[] arr)
  43.         {
  44.             int max = int.MinValue;
  45.  
  46.             for (int i = 0; i < arr.Length; i++)
  47.             {
  48.                 if (arr[i] > max)
  49.                 {
  50.                     max = arr[i];
  51.                 }
  52.             }
  53.  
  54.             return max;
  55.         }
  56.  
  57.         static void PrintHiglessElements(int x, int[] arr)
  58.         {
  59.             for (int i = 0; i < arr.Length; i++)
  60.             {
  61.                 if (arr[i] > x)
  62.                 {
  63.                     Console.WriteLine(arr[i]);
  64.                 }
  65.             }
  66.         }
  67.         static void Comb()
  68.         {
  69.             int n = int.Parse(Console.ReadLine());
  70.             int k = int.Parse(Console.ReadLine());
  71.  
  72.             int[] arr = new int[n];
  73.             int[] combinations = new int[k];
  74.  
  75.             for (int i = 0; i < n; i++)
  76.             {
  77.                 arr[i] = i + 1;
  78.             }
  79.  
  80.             Combinations(0, 0, arr, combinations);
  81.  
  82.             static void Combinations(int index, int elementsStartIndex, int[] elements, int[] combinations)
  83.             {
  84.                 if (index >= combinations.Length)
  85.                 {
  86.  
  87.                     foreach (int item in combinations)
  88.                     {
  89.                         Console.Write($"{item} ");
  90.                     }
  91.  
  92.                     Console.WriteLine();
  93.                 }
  94.                 else
  95.                 {
  96.                     for (int i = elementsStartIndex; i < elements.Length; i++)
  97.                     {
  98.                         combinations[index] = elements[i];
  99.                         Combinations(index + 1, i + 1, elements, combinations);
  100.                     }
  101.                 }
  102.             }
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement