Advertisement
Misipuk

task2_DT

Dec 8th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Task2
  9. {
  10.     class Program
  11.     {
  12.         static List<int> aList = new List<int>();
  13.         static HashSet<int> mSet = new HashSet<int>();
  14.         static int findM()
  15.         {
  16.             int m = 0;
  17.             for (int i = 0; i < 151; i++)
  18.             {
  19.                 if ((aList[i] > m) && (!mSet.Contains(aList[i]))){
  20.                     m = aList[i];
  21.                 }
  22.             }
  23.             mSet.Add(m);
  24.             return m;
  25.         }
  26.  
  27.         static void Main(string[] args)
  28.         {
  29.             List<int> bList = new List<int>();
  30.             Random rand = new Random();
  31.             int m = 0;
  32.             for(int i=0; i<151; i++)
  33.             {
  34.                 aList.Add(rand.Next(201));
  35.                // Console.WriteLine(aList[i]);
  36.             }
  37.             while (bList.Count() < 15)
  38.             {
  39.                 m = findM();
  40.                 //Console.WriteLine(m);
  41.                 for (int i = 0; i < 151; i++)
  42.                 {
  43.                     if (aList[i] == m)
  44.                     {
  45.                         if (bList.Count < 15)
  46.                         {
  47.                             bList.Add(m);
  48.                         }                      
  49.                     }
  50.                 }
  51.             }
  52.             StreamWriter f = new StreamWriter("test.txt");
  53.             Console.WriteLine("Your List:");
  54.             for (int i = 0; i < 15; i++)
  55.             {
  56.                // aList.Add(rand.Next(201));
  57.                  Console.WriteLine(bList[i]);
  58.                 f.WriteLine(bList[i]);
  59.             }
  60.             Console.WriteLine("File is located in bin/Debug");
  61.             f.Close();
  62.             Console.ReadLine();
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement