Created
June 3, 2015 15:32
-
-
Save vdonchev/42791c7e4d0c2914de7f to your computer and use it in GitHub Desktop.
MagicStrings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public class MagicStrings | |
{ | |
static void Main() | |
{ | |
int diff = int.Parse(Console.ReadLine()); | |
Dictionary<char, int> values = new Dictionary<char, int>(); | |
values.Add('k', 1); | |
values.Add('n', 4); | |
values.Add('p', 5); | |
values.Add('s', 3); | |
string firstSequence = string.Empty; | |
string secondSequence = string.Empty; | |
int firstSum = 0; | |
int secondSum = 0; | |
bool found = false; | |
if (diff > 16) | |
{ | |
Console.WriteLine("No"); | |
return; | |
} | |
foreach (KeyValuePair<char, int> first in values) | |
{ | |
foreach (KeyValuePair<char, int> second in values) | |
{ | |
foreach (KeyValuePair<char, int> third in values) | |
{ | |
foreach (KeyValuePair<char, int> fourth in values) | |
{ | |
firstSequence = Convert.ToString(first.Key) + second.Key + third.Key + fourth.Key; | |
firstSum = first.Value + second.Value + third.Value + fourth.Value; | |
// end first 4 digits | |
foreach (KeyValuePair<char, int> fifth in values) | |
{ | |
foreach (KeyValuePair<char, int> sixth in values) | |
{ | |
foreach (KeyValuePair<char, int> seventh in values) | |
{ | |
foreach (KeyValuePair<char, int> eighth in values) | |
{ | |
secondSequence = Convert.ToString(fifth.Key) + sixth.Key + seventh.Key + eighth.Key; | |
secondSum = fifth.Value + sixth.Value + seventh.Value + eighth.Value; | |
if (Math.Abs(firstSum - secondSum) == diff) | |
{ | |
Console.WriteLine(firstSequence + secondSequence); | |
found = true; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
if (found == false) | |
{ | |
Console.WriteLine("No"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment