NedyalkoKikov

CountNums - Dicitionaries

Jun 7th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CountNumbers
  8. {
  9. class CountNumbers
  10. {
  11. static void Main()
  12. {
  13. decimal[] nums = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  14. SortedDictionary<decimal, int> numbers = new SortedDictionary<decimal, int>();
  15. foreach(var num in nums)
  16. {
  17. numbers[num] = 0;
  18. }
  19. foreach(var num in nums)
  20. {
  21. numbers[num]++;
  22. }
  23. foreach(var n in numbers.Keys)
  24. {
  25. if(numbers[n] > 0)
  26. {
  27. Console.WriteLine("{0} -> {1}",n,numbers[n]);
  28. }
  29. }
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment