Advertisement
g-stoyanov

OrderGivenNumbersByOccuranceDemo

Feb 25th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. namespace NumberInputAndSorting
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, uint> numbers = new Dictionary<string, uint>();
  12.             string input = Console.ReadLine();
  13.             while (input != "stop")
  14.             {
  15.                 if (numbers.ContainsKey(input))
  16.                 {
  17.                     numbers[input]++;
  18.                 }
  19.                 else
  20.                 {
  21.                     numbers.Add(input, 1);
  22.                 }
  23.  
  24.                 input = Console.ReadLine();
  25.             }
  26.  
  27.             var result = numbers.OrderByDescending(x => x.Value);
  28.  
  29.             foreach (var number in result)
  30.             {
  31.                 Console.WriteLine("{0} -> {1}", number.Key, number.Value);
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement