Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CountOfOccurences
- {
- using System;
- using System.Linq;
- public static class CountOfOccurences
- {
- private const int MaxNumber = 1000;
- public static void Main()
- {
- var nums = new[] { 3, 4, 4, 2, 3, 3, 4, 3, 2 };
- var occurences = Enumerable.Repeat(0, MaxNumber + 1).ToList();
- foreach (var num in nums)
- {
- occurences[num]++;
- }
- for (int i = 0; i <= MaxNumber; i++)
- {
- if (occurences[i] != 0)
- {
- var number = occurences.IndexOf(occurences[i]);
- var times = occurences[i];
- Console.WriteLine($"{number} -> {times} times");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement