2022 sector 10 statements
This commit is contained in:
73
2022/sector/12/insule/insule.cpp
Normal file
73
2022/sector/12/insule/insule.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
ifstream input_stream;
|
||||
ofstream output_stream;
|
||||
|
||||
|
||||
void runMarkdown(bool mx[][100], bool mk[][100], uint16_t nodeX, uint16_t nodeY, uint8_t N) {
|
||||
mk[nodeY][nodeX] = true;
|
||||
|
||||
// Top
|
||||
if (nodeY - 1 >= 0 && mx[nodeY - 1][nodeX] && !mk[nodeY - 1][nodeX]) {
|
||||
runMarkdown(mx, mk, nodeX, nodeY - 1, N);
|
||||
}
|
||||
|
||||
// Bottom
|
||||
if (nodeY + 1 < N && mx[nodeY + 1][nodeX] && !mk[nodeY + 1][nodeX]) {
|
||||
runMarkdown(mx, mk, nodeX, nodeY + 1, N);
|
||||
}
|
||||
|
||||
// Left
|
||||
if (nodeX - 1 >= 0 && mx[nodeY][nodeX - 1] && !mk[nodeY][nodeX - 1]) {
|
||||
runMarkdown(mx, mk, nodeX - 1, nodeY, N);
|
||||
}
|
||||
|
||||
// Right
|
||||
if (nodeX + 1 < N && mx[nodeY][nodeX + 1] && !mk[nodeY][nodeX + 1]) {
|
||||
runMarkdown(mx, mk, nodeX + 1, nodeY, N);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
input_stream.open("Insule.txt");
|
||||
output_stream.open("output.txt");
|
||||
|
||||
uint16_t N;
|
||||
input_stream >> N;
|
||||
|
||||
bool matrix[N][100];
|
||||
bool marks[N][100];
|
||||
|
||||
for (uint8_t i = 0; i < N; i++) {
|
||||
for (uint8_t j = 0; j < N; j++) {
|
||||
input_stream >> matrix[i][j];
|
||||
marks[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t total = 0;
|
||||
|
||||
for (uint16_t i = 0; i < N; i++) {
|
||||
for (uint16_t j = 0; j < N; j++) {
|
||||
if (matrix[i][j] && !marks[i][j]) {
|
||||
runMarkdown(matrix, marks, j, i, N);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// File method:
|
||||
// output_stream << total << endl;
|
||||
// Console method:
|
||||
cout << total << endl;
|
||||
|
||||
input_stream.close();
|
||||
return 0;
|
||||
}
|
||||
7
2022/sector/12/insule/tests/insule1.txt
Normal file
7
2022/sector/12/insule/tests/insule1.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
6
|
||||
0 1 0 1 1 0
|
||||
1 1 0 0 1 1
|
||||
0 0 0 0 0 1
|
||||
1 0 1 0 0 0
|
||||
1 1 1 1 0 0
|
||||
0 0 0 0 1 1
|
||||
10
2022/sector/12/insule/tests/insule10.txt
Normal file
10
2022/sector/12/insule/tests/insule10.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
4
|
||||
1 1 1 1
|
||||
1 1 0 0
|
||||
0 0 1 1
|
||||
1 0 1 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4
2022/sector/12/insule/tests/insule2.txt
Normal file
4
2022/sector/12/insule/tests/insule2.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
3
|
||||
1 0 1
|
||||
0 0 0
|
||||
1 0 1
|
||||
8
2022/sector/12/insule/tests/insule3.txt
Normal file
8
2022/sector/12/insule/tests/insule3.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
7
|
||||
0 0 0 0 0 0 0
|
||||
0 0 1 1 0 0 1
|
||||
1 1 1 0 0 1 1
|
||||
0 0 0 1 0 0 0
|
||||
1 0 0 1 0 0 0
|
||||
1 1 0 0 1 1 1
|
||||
0 1 0 0 1 0 0
|
||||
6
2022/sector/12/insule/tests/insule4.txt
Normal file
6
2022/sector/12/insule/tests/insule4.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
5
|
||||
0 0 1 0 0
|
||||
0 0 1 0 0
|
||||
1 1 1 1 1
|
||||
0 1 0 0 0
|
||||
0 1 0 0 0
|
||||
5
2022/sector/12/insule/tests/insule5.txt
Normal file
5
2022/sector/12/insule/tests/insule5.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
4
|
||||
1 1 1 1
|
||||
0 1 0 0
|
||||
0 0 0 1
|
||||
0 0 1 1
|
||||
8
2022/sector/12/insule/tests/insule6.txt
Normal file
8
2022/sector/12/insule/tests/insule6.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
6
|
||||
1 1 0 1 1 0
|
||||
1 1 0 0 1 1
|
||||
0 0 0 1 1 1
|
||||
1 0 1 0 0 0
|
||||
1 0 1 1 1 0
|
||||
1 1 1 0 1 1
|
||||
|
||||
6
2022/sector/12/insule/tests/insule7.txt
Normal file
6
2022/sector/12/insule/tests/insule7.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
3
|
||||
0 0 0
|
||||
0 0 0
|
||||
0 0 0
|
||||
|
||||
|
||||
11
2022/sector/12/insule/tests/insule8.txt
Normal file
11
2022/sector/12/insule/tests/insule8.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
7
|
||||
0 0 1 1 0 1 0
|
||||
0 0 1 1 0 1 1
|
||||
1 1 1 1 0 1 1
|
||||
0 1 0 1 0 0 0
|
||||
1 1 0 1 1 0 0
|
||||
1 1 0 0 1 1 1
|
||||
0 1 0 0 1 0 0
|
||||
|
||||
|
||||
|
||||
10
2022/sector/12/insule/tests/insule9.txt
Normal file
10
2022/sector/12/insule/tests/insule9.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
5
|
||||
0 0 1 0 1
|
||||
0 1 1 1 0
|
||||
1 1 0 1 1
|
||||
0 1 0 1 1
|
||||
0 1 1 1 1
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user