TheBulgarianWolf

Count Real Numbers

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