-
Notifications
You must be signed in to change notification settings - Fork 0
/
1182B.cpp
76 lines (74 loc) · 1.76 KB
/
1182B.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
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
char a[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
int f=0;
int f1=0;
for(int i=1;i<n-1;i++){
for(int j=1;j<m-1;j++){
if(a[i][j]!='*')
continue;
//cout<<"r";
//cout<<"q";
if((a[i+1][j]!='*' || a[i-1][j]!='*' || a[i][j+1]!='*' || a[i][j-1]!='*')){
continue;
}
//cout<<"p";
// int u=0,d=0,r=0,l=0;
//cout<<i<<" "<<j<<"\n";
int i1=i;
int j1=j;
while(i1<n && a[i1+1][j1]=='*'){
i1++;
// u++;
a[i1][j1]='.';
}
i1=i;
j1=j;
while(i1>0 && a[i1-1][j1]=='*'){
i1--;
// d++;
a[i1][j1]='.';
}
i1=i;
j1=j;
while(j1>0 && a[i1][j1-1]=='*'){
j1--;
//l++;
a[i1][j1]='.';//cout<<i1<<" "<<j1<<"\n";
}
i1=i;
j1=j;
while(j1<n && a[i1][j1+1]=='*'){
j1++;
//r++;
a[i1][j1]='.';
}
a[i][j]='.';
f=1;
break;
}
if(f){
break;
}
}
// cout<<"\n\n\n";
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
// cout<<a[i][j];
if(a[i][j]=='*'){
cout<<"NO\n";
return 0;
}
}
// cout<<"\n";
}
cout<<"YES\n";
}