Skip to content

Instantly share code, notes, and snippets.

@dzas
Created November 21, 2019 20:53
Show Gist options
  • Save dzas/583a4d40bac466ac5ecc5e86908aa23b to your computer and use it in GitHub Desktop.
Save dzas/583a4d40bac466ac5ecc5e86908aa23b to your computer and use it in GitHub Desktop.
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Solution {
// Complete the sockMerchant function below.
static int sockMerchant(int n, int[] ar)
{
var socksByColor = new Dictionary<int, int>();
foreach (var color in ar)
{
if (socksByColor.TryGetValue(color, out var socks))
{
socks++;
}
else
{
socks = 1;
}
socksByColor[color] = socks;
}
int pairsTotal = 0;
foreach (var socksForColor in socksByColor)
{
var pairs = socksForColor.Value / 2;
pairsTotal += pairs;
}
return pairsTotal;
}
static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int n = Convert.ToInt32(Console.ReadLine());
int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp))
;
int result = sockMerchant(n, ar);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment