Advertisement
Guest User

StiliyanTest

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