csansoon

P8.06 P45829 Fields

Nov 29th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. typedef vector< vector<int> > Matrix;
  6.  
  7. int main(){
  8.     int nrows, ncols;
  9.  
  10.     while (cin >> nrows >> ncols){
  11.         int count = 0;
  12.        
  13.         Matrix field(nrows, vector<int>(ncols));
  14.        
  15.         for (int i=0; i<nrows; ++i){
  16.             for (int j=0; j<ncols; ++j){
  17.                 cin >> field[i][j];
  18.             }
  19.         }
  20.        
  21.         for (int i=0; i<nrows; ++i){
  22.             for (int j=0; j<ncols; ++j){
  23.                
  24.                 if (field[i][j]!=0){
  25.                     ++count;
  26.                     int r=0, d=0;
  27.                     for (int ii=i; ii<nrows  and field[ii][j]>0; ++ii) ++d;
  28.                     for (int jj=j; jj<ncols and field[i][jj]>0; ++jj) ++r;
  29.                    
  30.                    
  31.                     for (int h=0; h<d; ++h){
  32.                         for (int v=0; v<r; ++v){
  33.                             field[i+h][j+v] = 0;
  34.                         }
  35.                     }
  36.                 }
  37.             }
  38.         }
  39.        
  40.     cout << count << endl;
  41.     }
  42. }
  43.  
  44. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Advertisement
Add Comment
Please, Sign In to add comment