forked from Kiritow/OJ-Problems-Source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1813_Brandy.cpp
59 lines (56 loc) · 1.85 KB
/
1813_Brandy.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
#include <iostream>
using namespace std;
int R, C;
char map[1002][1002];
int sum = 0;
int main() {
cin >> R >> C;
char cu;
bool right = true;
for (int i = 1; i <= R; i++) {
for (int j = 1; j <= C; j++) {
cin >> cu;
map[i][j] = cu;
if (cu == '#') {
if (map[i - 1][j] == '#') {
if (map[i][j - 1] == '#' && map[i - 1][j - 1] == '#') {
continue;
}
if (map[i][j - 1] == '#' && map[i - 1][j - 1] != '#') {
right = false;
cout << "Bad placement.";
return 0;
}
if (map[i][j - 1] != '#' && map[i - 1][j - 1] == '#') {
right = false;
cout << "Bad placement.";
return 0;
}
if (map[i][j - 1] != '#' && map[i - 1][j - 1] != '#') {
continue;
}
} else {
if (map[i][j - 1] == '#' && map[i - 1][j - 1] == '#') {
right = false;
cout << "Bad placement.";
return 0;
}
if (map[i][j - 1] == '#' && map[i - 1][j - 1] != '#') {
continue;
}
if (map[i][j - 1] != '#' && map[i - 1][j - 1] == '#') {
sum++;
continue;
}
if (map[i][j - 1] != '#' && map[i - 1][j - 1] != '#') {
sum++;
continue;
}
}
}
}
}
cout << "There are " << sum << " ships.";
//system("pause");
return 0;
}