Advertisement
gabi11

Sets & Dictionaries Advanced - 1. Count Same Values in Array

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