C#
- 5 ответов
- 0 вопросов
2
Вклад в тег
using System;
using System.Collections.Generic;
namespace GetRepetitions
{
class Program
{
static void Main(string[] args)
{
var scoreCombo = new int[] { 1, 2, 1, 1, 1 };
var repetitions = GetRepetitionsCount(scoreCombo);
foreach (var kv in repetitions)
Console.WriteLine($"Num: {kv.Key}, Rep. Count: {kv.Value}");
}
static Dictionary<int, int> GetRepetitionsCount(int[] arr)
{
var repetitions = new Dictionary<int, int>();
foreach (var num in arr)
if (repetitions.ContainsKey(num))
repetitions[num]++;
else
repetitions.Add(num, 0);
return repetitions;
}
}
}