-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueen-bomb.cpp
More file actions
41 lines (38 loc) · 738 Bytes
/
Copy pathqueen-bomb.cpp
File metadata and controls
41 lines (38 loc) · 738 Bytes
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
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
int rows,cols;
char grid[110][110];
int x_bomb,y_bomb, count=0;
scanf("%d %d", &rows, &cols);
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cin >> grid[i][j];
if(grid[i][j] == '*')
{
x_bomb = i;
y_bomb = j;
}
}
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
if (grid[i][j] == 'P')
{
//same col, row or diagonal
if ((i == x_bomb || j == y_bomb) || (abs(x_bomb - i) == abs(y_bomb - j)))
count++;
}
}
}
printf("%d\n",count);
return 0;
}