Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>;
- using namespace std;
- const int n = 7;
- const int m = 5;
- int matr[7][3];
- void printm()
- {
- for (int i = 0; i < n; i++){
- for (int j = 0; j < m; j++)
- cout << matr[i][j];
- cout << endl;
- }
- }
- void paint(int x, int y, int color)
- {
- if (x<0 || x>n - 1 || y<0 || y>m - 1){
- return;
- }
- if (matr[x][y] != 0){
- return;
- }
- matr[x][y] = color;
- paint(x - 1, y, color);
- paint(x + 1, y, color);
- paint(x,y-1, color);
- paint(x ,y+1, color);
- }
- int main()
- {
- ifstream fin("C:\\Users\\TEMP.9_6\\Desktop\\text.txt");
- for (int i = 0; i < n; i++)
- for (int j = 0; j <m ; j++)
- fin >> matr[i][j];
- printm();
- int color = 2;
- int i = 0;
- for (int i = 0; i < n; i++)
- for (int j = 0; j <m; j++)
- if (matr[i][j] == 0){
- paint(1, j, color);
- //paint();
- color++;
- }
- printm();
- cout << color - 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement