Skip to content

Commit a8263bc

Browse files
Create Makoda and Childish Pranks.cpp
1 parent f7137e9 commit a8263bc

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
const int NO_OF_NEIGHBOURS = 4;
7+
const char BLACK = '1', WHITE = '0';
8+
int X[NO_OF_NEIGHBOURS] = {-1, 0, 0, 1}, Y[NO_OF_NEIGHBOURS] = {0, 1, -1, 0};
9+
10+
struct rectangle
11+
{
12+
int x1, y1, x2, y2;
13+
14+
rectangle(int X1, int Y1, int X2, int Y2)
15+
{
16+
x1 = X1 + 1;
17+
y1 = Y1 + 1;
18+
x2 = X2 + 1;
19+
y2 = Y2 + 1;
20+
}
21+
};
22+
23+
void solve()
24+
{
25+
int no_of_rows, no_of_columns;
26+
cin >> no_of_rows >> no_of_columns;
27+
28+
vector <string> grid(no_of_rows);
29+
for(int i = 0; i < no_of_rows; i++)
30+
{
31+
cin >> grid[i];
32+
}
33+
34+
if(grid[0][0] == BLACK)
35+
{
36+
cout << "-1\n";
37+
return;
38+
}
39+
40+
vector <rectangle> moves;
41+
for(int i = no_of_rows - 1; i >= 0; i--)
42+
{
43+
for(int j = no_of_columns - 1; j >= 0; j--)
44+
{
45+
if(grid[i][j] == BLACK)
46+
{
47+
if(j > 0)
48+
{
49+
moves.push_back(rectangle(i, j - 1, i, j));
50+
}
51+
else if(i > 0)
52+
{
53+
moves.push_back(rectangle(i - 1, j, i, j));
54+
}
55+
}
56+
}
57+
}
58+
59+
cout << moves.size() << "\n";
60+
for(rectangle current_rectangle : moves)
61+
{
62+
cout << current_rectangle.x1 << " " << current_rectangle.y1 << " " << current_rectangle.x2 << " " << current_rectangle.y2 << "\n";
63+
}
64+
}
65+
66+
int main()
67+
{
68+
int no_of_test_cases;
69+
cin >> no_of_test_cases;
70+
71+
while(no_of_test_cases--)
72+
solve();
73+
74+
return 0;
75+
}
76+
77+
78+
79+
80+

0 commit comments

Comments
 (0)