Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement