svetlozar_kirkov

Magic Strings

Sep 22nd, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace MagicStrings
  6. {
  7.     class MagicStrings
  8.     {
  9.         static void Main()
  10.         {
  11.             int diff = int.Parse(Console.ReadLine());
  12.             string[] letters = new string[4] { "s", "n", "k", "p" };
  13.             int[] lettersWeight = new int[4] { 3, 4, 1, 5 };
  14.             int count = 0;
  15.             List<string> collected = new List<string>();
  16.  
  17.             for (int i = 0; i < 4; i++)
  18.             {
  19.                 for (int j = 0; j < 4; j++)
  20.                 {
  21.                     for (int k = 0; k < 4; k++)
  22.                     {
  23.                         for (int m = 0; m < 4; m++)
  24.                         {
  25.                             for (int n = 0; n < 4; n++)
  26.                             {
  27.                                 for (int o = 0; o < 4; o++)
  28.                                 {
  29.                                     for (int p = 0; p < 4; p++)
  30.                                     {
  31.                                         for (int q = 0; q < 4; q++)
  32.                                         {
  33.                                             string[] temp = new string[8] {letters[i],letters[j],letters[k],letters[m],
  34.                                                 letters[n], letters[o], letters[p], letters[q]};
  35.                                             int[] tempInt = new int[8] {lettersWeight[i], lettersWeight[j], lettersWeight[k],
  36.                                             lettersWeight[m], lettersWeight[n], lettersWeight[o], lettersWeight[p],
  37.                                             lettersWeight[q]};
  38.  
  39.                                             int tempSumLeft = tempInt[0] + tempInt[1] + tempInt[2] + tempInt[3];
  40.                                             int tempSumRight = tempInt[4] + tempInt[5] + tempInt[6] + tempInt[7];
  41.  
  42.                                             if (tempSumRight-tempSumLeft == diff || tempSumLeft-tempSumRight == diff)
  43.                                             {
  44.                                                 string collect = string.Join("", temp);
  45.                                                 collected.Add(collect);
  46.                                                 count++;
  47.                                             }
  48.                                            
  49.                                         }
  50.                                     }
  51.                                 }
  52.                             }
  53.                         }
  54.                     }
  55.                 }
  56.             }
  57.  
  58.             if (count == 0)
  59.             {
  60.                 Console.WriteLine("No");
  61.             }
  62.             else
  63.             {
  64.                 collected.Sort();
  65.                 foreach (var item in collected)
  66.                 {
  67.                     Console.WriteLine(item);
  68.                 }
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment