Advertisement
desislava_topuzakova

Problem 11.Честота на срещания

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