-
Notifications
You must be signed in to change notification settings - Fork 148
/
neighbours.cpp
90 lines (90 loc) · 1.74 KB
/
neighbours.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
char arr[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>arr[i][j];
}
}
int i,j;//taking the position of x and y
cin>>i>>j;
i=i-1;
j=j-1;
//making x and y accoring to index of the array
bool c1=false,c2=false,c3=false,c4=false,c5=false,c6=false,c7=false,c8=false;//initialising first the condition of all the neightbours false and the checking one by one each
if(arr[i-1][j]=='x')//for upwards
{
c1=true;
}
if(arr[i+1][j]=='x')//for downwards
{
c2=true;
}
if(arr[i][j-1]=='x')//for left
{
c3=true;
}
if(arr[i][j+1]=='x')//for right
{
c4=true;
}
if(arr[i-1][j+1]=='x')//for corner upright
{
c5=true;
}
if(arr[i-1][j-1]=='x')//for corner upleft
{
c6=true;
}
if(arr[i+1][j-1]=='x')//for corner downleft
{
c7=true;
}
if(arr[i+1][j+1]=='x')//for downright
{
c8=true;
}
if(i==0)//cornercase for i==0
{
c1=true;
c6=true;
if(j==0)//cornercase j==0
{
c3=true;
}
c5=true;
if(j==m-1)//for cornercase j==m-1
{
c4=true;
}
}
if(i==n-1)//for cornercase i==n-1
{
c2==true;
c7=true;
c8=true;
if(j==0)//for cornercase j==0
{
c3=true;
}
if(j==m-1)//for cornercase j==m-1
{
c4=true;
}
}
if(c1 && c2 && c3 && c4 && c5 && c6 && c7 && c8)
{
cout<<"yes"<<endl;
}
else{
cout<<"no"<<endl;
}
return 0;
}