Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. namespace CountOfOccurences
  2. {
  3. using System;
  4. using System.Linq;
  5.  
  6. public static class CountOfOccurences
  7. {
  8. private const int MaxNumber = 1000;
  9.  
  10. public static void Main()
  11. {
  12. var nums = new[] { 3, 4, 4, 2, 3, 3, 4, 3, 2 };
  13. var occurences = Enumerable.Repeat(0, MaxNumber + 1).ToList();
  14.  
  15. foreach (var num in nums)
  16. {
  17. occurences[num]++;
  18. }
  19.  
  20. for (int i = 0; i <= MaxNumber; i++)
  21. {
  22. if (occurences[i] != 0)
  23. {
  24. var number = occurences.IndexOf(occurences[i]);
  25. var times = occurences[i];
  26.  
  27. Console.WriteLine($"{number} -> {times} times");
  28. }
  29. }
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement