Initial commit

This commit is contained in:
2022-06-01 20:14:50 +03:00
commit 8b9cce4739
1094 changed files with 68851 additions and 0 deletions

View 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;
}