SHARE
TWEET

OrderGivenNumbersByOccuranceDemo

g-stoyanov Feb 25th, 2015 185 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top