Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Making Anagrams
//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); } ArrayList confirm = new ArrayList(); /* foreach (KeyValuePair<char, int> kvp in aDic.ToList()) { // Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); if(kvp.Value == 1){ confirm.Add( kvp.Key); // aDic.Remove(kvp.Key); } else{ if(aOrignal.Contains(kvp.Key) && bOrignal.Contains(kvp.Key)){ if(kvp.Value % 2 == 0){ aDic.Remove(kvp.Key); } else{ aDic[kvp.Key] -=2; } } } // Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } Console.WriteLine(String.Join(" ",confirm.ToArray()));*/ 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; } } } } // Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } int count = 0; foreach (KeyValuePair<char, int> kvp in bDic) { count += kvp.Value; // Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } foreach (KeyValuePair<char, int> kvp in aDic) { count += kvp.Value; // Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } Console.WriteLine(count); //end } } }
run
|
edit
|
history
|
help
0
Collatz Conjecture
30272 Program Ex1
a
Random number between 1 - 100 between each value of 10 there will be a differnt message
asdfrtgeryrutu
Linear search
11
Lesson1
Main 5.5
Fibonacci