Advertisement
martinvalchev

Count Real Numbers

Feb 15th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Demo
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             double[] numbers = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  12.             var count = new SortedDictionary<double, int>();
  13.  
  14.             foreach (var num in numbers)
  15.             {
  16.                 if (count.ContainsKey(num))
  17.                 {
  18.                     count[num]++;
  19.                 }
  20.                 else
  21.                 {
  22.                     count.Add(num, 1);
  23.                 }
  24.             }
  25.  
  26.                 foreach (var num in count)
  27.                 {
  28.                 Console.WriteLine($"{num.Key} -> {num.Value}");
  29.                 }
  30.                
  31.             }
  32.            
  33.  
  34.             }
  35.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement