Advertisement
Guest User

Most Frequent Number

a guest
May 28th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1.             char[] separators = new char[] { ' ', ';' };
  2.             string[] sentence = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
  3.  
  4.             var query = (from i in sentence
  5.                          group i by i into g
  6.                          orderby g.Count() descending
  7.                          select new { Key = g.Key, Count = g.Count() }).FirstOrDefault();
  8.  
  9.             if (query == null)
  10.             {
  11.                 Console.WriteLine("query = NULL");
  12.             }
  13.             else
  14.             {
  15.                 Console.WriteLine("{0}", query.Key);
  16.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement