Skip to content

Instantly share code, notes, and snippets.

@unilecs
Last active December 22, 2017 06:14
Show Gist options
  • Save unilecs/3bf1ad6423b2123e0ee7cd0ed8c044e2 to your computer and use it in GitHub Desktop.
Save unilecs/3bf1ad6423b2123e0ee7cd0ed8c044e2 to your computer and use it in GitHub Desktop.
Задача 55: Квадраты
using System;
using System.Collections.Generic;
public class Program
{
public static int GetCountOfSquares(int[] values)
{
// соберем словарик: длина отрезка -> кол-во таких отрезков
var hashMap = new Dictionary<int, int>();
for (int i = 0; i < values.Length; i++)
{
int value = values[i];
if (hashMap.ContainsKey(value))
{
hashMap[value]++;
}
else
{
hashMap[value] = 1;
}
}
int result = 0;
foreach (var item in hashMap)
{
result += item.Value / 4; // берем целую часть от деления
}
return result;
}
public static void Main()
{
Console.WriteLine("@UniLecs");
int[] arr = new int[] { 7, 7, 2, 7, 8, 7, 9, 7, 2 };
Console.WriteLine(GetCountOfSquares(arr)); // 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment