Advertisement
stoianpp

linear 8

Mar 16th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. //* The majorant of an array of size N is a value that occurs in it at least N/2 + 1 times.
  6. //Write a program to find the majorant of given array (if exists).
  7.  
  8. class Task8
  9. {
  10.     static void Main()
  11.     {
  12.         List<int> list = new List<int>() {1,2,2,1,1,1,1,4,4,2,1};
  13.         var result = list.GroupBy(k => k).ToDictionary(g => g.Key, g => g.Count());
  14.         foreach (var item in result)
  15.         {
  16.             if (item.Value > list.Count / 2) Console.WriteLine(item.Key);
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement