-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
53 lines (50 loc) · 1.08 KB
/
B.cpp
File metadata and controls
53 lines (50 loc) · 1.08 KB
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
#include<iostream>
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 c=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]=='W')
{
if(j-1>=0 && a[i][j-1]=='P')
{
a[i][j]='.';
a[i][j-1]='.';
c++;
}
else if(i-1>=0 && a[i-1][j]=='P')
{
a[i][j]='.';
a[i-1][j]='.';
c++;
}
else if(j+1<m && a[i][j+1]=='P')
{
a[i][j]='.';
a[i][j+1]='.';
c++;
}
else if(i+1<n && a[i+1][j]=='P')
{
a[i][j]='.';
a[i+1][j]='.';
c++;
}
}
}
}
cout<<c;
}