Advertisement
Pavle_nis

Untitled

Apr 1st, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp69
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = Convert.ToInt32(Console.ReadLine());
  14.             List<int> list = new List<int>();
  15.             List<int> list1 = new List<int>();
  16.             for (int i = 1; i <= n; i++)
  17.             {
  18.                 list = Console.ReadLine().Split(',').Select(Int32.Parse).ToList();
  19.                 list1.AddRange(list);
  20.             }
  21.  
  22.             Dictionary<int, int> brojevi = new Dictionary<int, int>();
  23.             brojevi = list1.GroupBy(x => x).OrderByDescending(x => x.Count()).ToDictionary(y => y.Key, y => y.Count());
  24.  
  25.             Console.WriteLine("\n");
  26.  
  27.             for(int i = 0; i < 6; i++)
  28.             {
  29.                 Console.WriteLine(brojevi.ElementAt(i).Key);
  30.             }
  31.  
  32.             Console.ReadKey();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement