Advertisement
ZhilinskiyG

куски бумаги

Apr 23rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>;
  4. using namespace std;
  5.  
  6. const int n = 7;
  7. const int m = 5;
  8.  
  9. int matr[7][3];
  10.  
  11. void printm()
  12. {
  13.     for (int i = 0; i < n; i++){
  14.         for (int j = 0; j < m; j++)
  15.             cout << matr[i][j];
  16.         cout << endl;
  17.     }
  18. }
  19.  
  20. void paint(int x, int y, int color)
  21. {
  22.     if (x<0 || x>n - 1 || y<0 || y>m - 1){
  23.         return;
  24.     }
  25.     if (matr[x][y] != 0){
  26.         return;
  27.     }
  28.     matr[x][y] = color;
  29.     paint(x - 1, y, color);
  30.     paint(x + 1, y, color);
  31.     paint(x,y-1, color);
  32.     paint(x ,y+1, color);
  33. }
  34.  
  35. int main()
  36. {
  37.     ifstream fin("C:\\Users\\TEMP.9_6\\Desktop\\text.txt");
  38.     for (int i = 0; i < n; i++)
  39.         for (int j = 0; j <m ; j++)
  40.             fin >> matr[i][j];
  41.     printm();
  42.     int color = 2;
  43.     int i = 0;
  44.     for (int i = 0; i < n; i++)
  45.         for (int j = 0; j <m; j++)
  46.             if (matr[i][j] == 0){
  47.                 paint(1, j, color);
  48.                 //paint();
  49.                 color++;
  50.             }
  51.     printm();
  52.     cout << color - 1;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement