Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- //* The majorant of an array of size N is a value that occurs in it at least N/2 + 1 times.
- //Write a program to find the majorant of given array (if exists).
- class Task8
- {
- static void Main()
- {
- List<int> list = new List<int>() {1,2,2,1,1,1,1,4,4,2,1};
- var result = list.GroupBy(k => k).ToDictionary(g => g.Key, g => g.Count());
- foreach (var item in result)
- {
- if (item.Value > list.Count / 2) Console.WriteLine(item.Key);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement