-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathads.cpp
More file actions
92 lines (92 loc) · 2.44 KB
/
ads.cpp
File metadata and controls
92 lines (92 loc) · 2.44 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
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
91
92
// GitHub: EntityPlantt/Kattis
#include <iostream>
#include <vector>
using namespace std;
struct coord {
int x, y;
coord(int x = 0, int y = 0) {
this->x = x;
this->y = y;
}
};
struct rect {
coord upLeft, downRight;
rect(coord upLeft, coord downRight) {
this->upLeft = upLeft;
this->downRight = downRight;
}
};
int w, h;
string page[w];
vector <rect> images;
void discoverImage(coord crd) {
images.push_back(rect(crd));
while (crd.x < w && page[crd.x][crd.y] == '+') {
crd.x++;
}
while (crd.y < h && page[crd.x][crd.y] == '+') {
crd.y++;
}
images.back().downRight = crd;
}
vector <int> subImages(rect bounds) {
vector <int> ret;
for (int i = 0; i < images.size(); i++) {
if (images[i].upLeft.x < bounds.upLeft.x
&& images[i].upLeft.y < bounds.upLeft.y
&& images[i].downRight.x > bounds.downRight.x
&& images[i].downRight.y > bounds.downRight.y) {
ret.push_back(i);
}
}
return ret;
}
bool isAd(rect image) {
for (coord i = image.upLeft; i.x < image.downRight.x; i++) {
for (i.y = image.upLeft.y; i.y < image.downRight.y; i++) {
if (isdigit(page[i.x][i.y])
|| isupper(page[i.x][i.y])
|| islower(page[i.x][i.y])
|| page[i.x][i.y] == '?'
|| page[i.x][i.y] == '!'
|| page[i.x][i.y] == ','
|| page[i.x][i.y] == '.'
|| page[i.x][i.y] == ' '
|| page[i.x][i.y] == '+'
) {
continue;
}
return true;
}
}
return false;
}
void removeImage(int image) {
for (coord i = images[image].upLeft; i.x < images[image].downRight.x; i++) {
for (i.y = images[image].upLeft.y; i.y < images[image].downRight.y; i++) {
page[i.x][i.y] = ' ';
}
}
images.erase(images.begin() + image);
}
int main() {
cin >> w >> h;
for (int i = 0; i < w; i++) {
getline(cin, page[i]);
}
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
if (page[i][j] == '+') {
if (i > 0 && page[i - 1][j] != '+'
|| j > 0 && page[i][j - 1] != '+') {
continue;
}
discoverImage({i, j});
}
}
}
vector <int> imageStack;
while (!images.empty()) {
// PLEASE FINISH MEEEEEEEeeeee!!!
}
}