zh_stoqnov

Magic Strings

Oct 26th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Magic_Strings
  4. {
  5. class MagicStrings
  6. {
  7. public static void Main(string[] args)
  8. {
  9. int diff = int.Parse(Console.ReadLine());
  10. char[] symbols = {'k', 'n', 'p', 's'};
  11. int count = 0;
  12. for(int d1 = 0; d1 < symbols.Length; d1++)
  13. {
  14. for(int d2 = 0; d2 < symbols.Length; d2++)
  15. {
  16. for(int d3 = 0; d3 < symbols.Length; d3++)
  17. {
  18. for(int d4 = 0; d4 < symbols.Length; d4++)
  19. {
  20. string str = "" + symbols[d1] + symbols[d2] + symbols[d3] + symbols[d4];
  21. int firstSum = Sum(str);
  22. for(int d5 = 0; d5 < symbols.Length; d5++)
  23. {
  24. for (int d6 = 0; d6 < symbols.Length; d6++)
  25. {
  26. for (int d7 = 0; d7 < symbols.Length; d7++)
  27. {
  28. for (int d8 = 0; d8 < symbols.Length; d8++)
  29. {
  30. string str2 = "" + symbols[d5] + symbols[d6] + symbols[d7] + symbols[d8];
  31. int secondSum = Sum(str2);
  32. if (Math.Abs(secondSum - firstSum) == diff)
  33. {
  34. Console.WriteLine("{0}{1}", str, str2);
  35. count++;
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
  45. if (count == 0)
  46. {
  47. Console.WriteLine("No");
  48. }
  49.  
  50. }
  51. private static int Sum (string str)
  52. {
  53. int weight = 0;
  54. foreach (var ch in str)
  55. {
  56. switch(ch)
  57. {
  58. case 's': weight += 3; break;
  59. case 'n': weight += 4; break;
  60. case 'k': weight += 1; break;
  61. case 'p': weight += 5; break;
  62. }
  63. }
  64. return weight;
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment