Skip to content

Instantly share code, notes, and snippets.

@careyi3
Created March 18, 2018 17:37
Show Gist options
  • Save careyi3/32ffd6cdd88d598eff23504d202a8756 to your computer and use it in GitHub Desktop.
Save careyi3/32ffd6cdd88d598eff23504d202a8756 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static void Main(String[] args) {
string a = Console.ReadLine();
string b = Console.ReadLine();
a = String.Concat(a.OrderBy(c => c));
b = String.Concat(b.OrderBy(c => c));
if(a == b)
{
Console.WriteLine(0);
}
var dica = a.GroupBy(x => x).ToDictionary(x => x.Key, g => g.Count());
var dicb = b.GroupBy(x => x).ToDictionary(x => x.Key, g => g.Count());
var sum = 0;
var diffa = dica.Except(dicb).ToDictionary(s => s.Key, s=>s.Value);
var diffb = dicb.Except(dica).ToDictionary(s => s.Key, s=>s.Value);
foreach(var apair in diffa)
{
if(diffb.ContainsKey(apair.Key))
{
sum += Math.Abs(apair.Value-diffb[apair.Key]);
diffb.Remove(apair.Key);
}
else
{
sum += apair.Value;
}
}
sum += diffb.Sum(x => x.Value);
Console.WriteLine(sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment