Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. unsigned counter(int matrix[6][6], unsigned num)
  4. {
  5. unsigned counter = 0;
  6.  
  7. if (num < 10)
  8. {
  9. for (size_t y = 0; y < 6; y++)
  10. {
  11. for (size_t x = 0; x < 6; x++)
  12. {
  13. if (num == matrix[y][x])
  14. {
  15. counter++;
  16. }
  17. }
  18. }
  19. }
  20. else
  21. {
  22. size_t numLength = 1;
  23. for (int n = num / 10; n; n /= 10) numLength++;
  24.  
  25. for (size_t y = 0; y < 6; y++)
  26. {
  27. for (size_t x = 0; x < 6; x++)
  28. {
  29. if (6 - x >= numLength)
  30. {
  31. unsigned length = 0;
  32. for (int n = num; n != 0; n /= 10)
  33. {
  34. if (n % 10 == matrix[y][x + length] && ++length == numLength) counter++;
  35. }
  36. }
  37. if (x + 1 >= numLength)
  38. {
  39. unsigned length = 0;
  40. for (int n = num; n != 0; n /= 10)
  41. {
  42. if (n % 10 == matrix[y][x - length] && ++length == numLength) counter++;
  43. }
  44. }
  45. if (6 - y >= numLength)
  46. {
  47. unsigned length = 0;
  48. for (int n = num; n != 0; n /= 10)
  49. {
  50. if (n % 10 == matrix[y + length][x] && ++length == numLength) counter++;
  51. }
  52. }
  53. if (y + 1 >= numLength)
  54. {
  55. unsigned length = 0;
  56. for (int n = num; n != 0; n /= 10)
  57. {
  58. if (n % 10 == matrix[y - length][x] && ++length == numLength) counter++;
  59. }
  60. }
  61. }
  62. }
  63. }
  64.  
  65. return counter;
  66. }
  67.  
  68.  
  69. int main()
  70. {
  71. int matrix[6][6] =
  72. { 2,4,3,6,8,9,
  73. 4,5,4,7,0,1,
  74. 1,4,5,6,7,8,
  75. 5,0,8,9,8,6,
  76. 3,2,4,6,8,0,
  77. 2,4,6,7,9,0 };
  78.  
  79. int counted = counter(matrix, 80);
  80.  
  81. std::cout << counted << std::endl;
  82.  
  83. int x;
  84. std::cin >> x;
  85.  
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement