Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Magic_Strings
- {
- class MagicStrings
- {
- public static void Main(string[] args)
- {
- int diff = int.Parse(Console.ReadLine());
- char[] symbols = {'k', 'n', 'p', 's'};
- int count = 0;
- for(int d1 = 0; d1 < symbols.Length; d1++)
- {
- for(int d2 = 0; d2 < symbols.Length; d2++)
- {
- for(int d3 = 0; d3 < symbols.Length; d3++)
- {
- for(int d4 = 0; d4 < symbols.Length; d4++)
- {
- string str = "" + symbols[d1] + symbols[d2] + symbols[d3] + symbols[d4];
- int firstSum = Sum(str);
- for(int d5 = 0; d5 < symbols.Length; d5++)
- {
- for (int d6 = 0; d6 < symbols.Length; d6++)
- {
- for (int d7 = 0; d7 < symbols.Length; d7++)
- {
- for (int d8 = 0; d8 < symbols.Length; d8++)
- {
- string str2 = "" + symbols[d5] + symbols[d6] + symbols[d7] + symbols[d8];
- int secondSum = Sum(str2);
- if (Math.Abs(secondSum - firstSum) == diff)
- {
- Console.WriteLine("{0}{1}", str, str2);
- count++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (count == 0)
- {
- Console.WriteLine("No");
- }
- }
- private static int Sum (string str)
- {
- int weight = 0;
- foreach (var ch in str)
- {
- switch(ch)
- {
- case 's': weight += 3; break;
- case 'n': weight += 4; break;
- case 'k': weight += 1; break;
- case 'p': weight += 5; break;
- }
- }
- return weight;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment