Advertisement
georgimanov

04 FiveSpecialLetters

Apr 14th, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _3.Problem
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int start = int.Parse(Console.ReadLine());
  14. int end = int.Parse(Console.ReadLine());
  15. bool printResult = false;
  16.  
  17. char[] arr = { 'a', 'b', 'c', 'd', 'e' };
  18.  
  19. long weight = 0;
  20.  
  21. string sequence = "";
  22.  
  23. StringBuilder uniqueSequence = new StringBuilder();
  24.  
  25. for (int a = 0; a < arr.Length; a++)
  26. {
  27. for (int b = 0; b < arr.Length; b++)
  28. {
  29. for (int c = 0; c < arr.Length; c++)
  30. {
  31. for (int d = 0; d < arr.Length; d++)
  32. {
  33. for (int e = 0; e < arr.Length; e++)
  34. {
  35. Object[] objs = new Object[] {arr[a], arr[b], arr[c], arr[d], arr[e]};
  36.  
  37. sequence = String.Concat(objs);
  38.  
  39. string answer = new string(sequence.Distinct().ToArray());
  40.  
  41. char[] arrayOfChars = new char[answer.Length];
  42.  
  43. for (int i = 0; i < answer.Length; i++)
  44. {
  45. arrayOfChars[i] = answer[i];
  46. }
  47.  
  48. for (int i = 0; i < answer.Length; i++)
  49. {
  50. weight += calculateLetter(arrayOfChars, i) * (i + 1);
  51. }
  52.  
  53. if (weight >= start && weight <= end)
  54. {
  55. Console.Write("{0} ", sequence, weight);
  56. printResult = true;
  57. }
  58.  
  59. weight = 0;
  60. }
  61. }
  62. }
  63. }
  64. }
  65. if (!printResult)
  66. {
  67. Console.WriteLine("No");
  68. }
  69. }
  70.  
  71.  
  72. private static int calculateLetter(char[] arr, int position)
  73. {
  74. int weightLetter = 0;
  75.  
  76. switch (arr[position])
  77. {
  78. case 'a': weightLetter = 5; break;
  79. case 'b': weightLetter = -12; break;
  80. case 'c': weightLetter = 47; break;
  81. case 'd': weightLetter = 7; break;
  82. case 'e': weightLetter = -32; break;
  83.  
  84. default:
  85. break;
  86. }
  87. return weightLetter;
  88. }
  89.  
  90.  
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement