Advertisement
Guest User

Untitled

a guest
May 30th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Majorant
  6. {
  7.     class Majorant
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> numbers = new List<int>() { 2, 2, 3, 3, 2, 3, 4, 3, 3 };
  12.             int majorantFormula = (numbers.Count / 2) + 1;
  13.  
  14.             var groupedNumbers = numbers.GroupBy(x => x);
  15.  
  16.             string result = string.Empty;
  17.             foreach (var group in groupedNumbers)
  18.             {
  19.                 if (group.Count() == majorantFormula)
  20.                 {
  21.                     result = string.Format("The majorant is: {0}", group.First());
  22.                 }
  23.                 else if (result == string.Empty)
  24.                 {
  25.                     result = "The majorant does not exists!";
  26.                 }
  27.             }
  28.  
  29.             Console.WriteLine(result);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement