Boris-Stavrev92

Untitled

Jul 1st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. using System;
  2.  
  3. class MagicCarNumbers
  4. {
  5. static int count = 0;
  6.  
  7. static void Main()
  8. {
  9. int magicWeight = int.Parse(Console.ReadLine());
  10.  
  11. char[] letters = { 'A', 'B', 'C', 'E', 'H', 'K', 'M', 'P', 'T', 'X' };
  12.  
  13. for (int l1 = 0; l1 < letters.Length; l1++)
  14. {
  15. for (int l2 = 0; l2 < letters.Length; l2++)
  16. {
  17. for (int a = 0; a <= 9; a++)
  18. {
  19. CheckCarNumber("CA" + a + a + a + a + letters[l1] + letters[l2], magicWeight);
  20. for (int b = 0; b <= 9; b++)
  21. {
  22. if (b != a)
  23. {
  24. CheckCarNumber("CA" + a + a + a + b + letters[l1] + letters[l2], magicWeight);
  25. CheckCarNumber("CA" + a + b + b + b + letters[l1] + letters[l2], magicWeight);
  26. CheckCarNumber("CA" + a + a + b + b + letters[l1] + letters[l2], magicWeight);
  27. CheckCarNumber("CA" + a + b + a + b + letters[l1] + letters[l2], magicWeight);
  28. CheckCarNumber("CA" + a + b + b + a + letters[l1] + letters[l2], magicWeight);
  29. }
  30. }
  31. }
  32. }
  33. }
  34.  
  35. Console.WriteLine(count);
  36. }
  37.  
  38. static void CheckCarNumber(string carNumber, int magicSum)
  39. {
  40. int weight = 0;
  41. foreach (var ch in carNumber)
  42. {
  43. if (ch >= '0' && ch <= '9')
  44. {
  45. weight += (ch - '0');
  46. }
  47. else
  48. {
  49. weight += (10 * (ch - 'A' + 1));
  50. }
  51. }
  52.  
  53. if (weight == magicSum)
  54. {
  55. count++;
  56. //Console.WriteLine(carNumber);
  57. }
  58. }
  59. }
Add Comment
Please, Sign In to add comment