Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Making Anagrams-Final
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Collections; namespace Rextester { public class Program { private void MyMethod(Dictionary<char,int> myDictionary) { } public static void Main(string[] args) { //Your code goes here string a = Console.ReadLine(); string b = Console.ReadLine(); char[] aO = a.Trim().Replace(" ","").ToLower().ToCharArray(); Array.Sort(aO); char[] bO = b.Trim().Replace(" ","").ToLower().ToCharArray(); Array.Sort(bO); ArrayList aOrignal = new ArrayList(); aOrignal.AddRange(aO); ArrayList bOrignal = new ArrayList(); bOrignal.AddRange(bO); Dictionary<char, int> aDic = new Dictionary<char, int>(); foreach(char item in aOrignal) { if (aDic.ContainsKey(item)) aDic[item]++; else aDic.Add(item, 1); } Dictionary<char, int> bDic = new Dictionary<char, int>(); foreach(char item in bOrignal) { if (bDic.ContainsKey(item)) bDic[item]++; else bDic.Add(item, 1); } foreach (KeyValuePair<char, int> kvp in aDic.ToList()) { if(aOrignal.Contains(kvp.Key) && bOrignal.Contains(kvp.Key)){ aDic[kvp.Key] -=1; bDic[kvp.Key] -=1; for(var i=1; i<kvp.Value;i++){ if(aDic.ContainsKey(kvp.Key) && bDic.ContainsKey(kvp.Key)){ if(aDic[kvp.Key] > 0 && bDic[kvp.Key] >0 ){ aDic[kvp.Key] -=1; bDic[kvp.Key] -=1; } } } } } int count = 0; foreach (KeyValuePair<char, int> kvp in bDic) { count += kvp.Value; } foreach (KeyValuePair<char, int> kvp in aDic) { count += kvp.Value; } Console.WriteLine(count); //end } } }
run
|
edit
|
history
|
help
0
Hei
ConcurrentQueue<T>
Arreglo
Print 2D Array
30272 Program Ex5_1 if else_2
Custom thousand separator
test linq select
line 1 syntax error
Primes
dsrlkgjrekt