Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp> // Common file
  3. #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
  4. #define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  5.  
  6. using namespace std;
  7. using namespace __gnu_pbds;
  8. using ll = long long;
  9.  
  10. template<typename key> using ordered_set = tree <key, null_type, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
  11.  
  12. char arr[8][8];
  13.  
  14. bool checkRow(int r, int c) {
  15. for(int i = c + 1; i < 8; i++) {
  16. if(arr[r][i] == '*')
  17. return true;
  18. }
  19. return false;
  20. }
  21.  
  22. bool checkCol(int r, int c) {
  23. for(int i = r + 1; i < 8; i++) {
  24. if(arr[i][c] == '*')
  25. return true;
  26. }
  27. return false;
  28. }
  29.  
  30. bool checkDiag(int r, int c) {
  31. for(int i = r + 1, j = c + 1; i < 8 && j < 8; i++, j++) {
  32. if(arr[i][j] == '*') {
  33. return true;
  34. }
  35. }
  36. for(int i = r + 1, j = c - 1; i < 8 && j >= 0; i++, j--) {
  37. if(arr[i][j] == '*') {
  38. return true;
  39. }
  40. }
  41. for(int i = r - 1, j = c + 1; i >= 0 && j < 8; i--, j++) {
  42. if(arr[i][j] == '*') {
  43. return true;
  44. }
  45. }
  46. for(int i = r - 1, j = c - 1; i >= 0 && j >= 0; i--, j--) {
  47. if(arr[i][j] == '*') {
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53.  
  54. int main() {
  55. IO;
  56. for(int i = 0; i < 8; i++) {
  57. for(int j = 0; j < 8; j++)
  58. cin >> arr[i][j];
  59. }
  60. for(int i = 0; i < 8; i++) {
  61. for(int j = 0; j < 8; j++) {
  62. if(arr[i][j] == '*') {
  63. if(checkRow(i, j) || checkCol(i, j) || checkDiag(i, j)) {
  64. return cout << "invalid", 0;
  65. }
  66. }
  67. }
  68. }
  69. cout << "valid";
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement