Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct cell
  5. {
  6.     bool full;
  7.     int near;
  8.     int generation;
  9.    
  10.     cell()
  11.         :full(false), near(0), generation(0) { };
  12.     cell(bool full)
  13.         :full(full), near(0), generation(0) { };
  14.        
  15.     void NearCellStatusChanged(bool status)
  16.     {
  17.         if (status == true)
  18.             near++;
  19.         else near--;
  20.  
  21.         if (near == 3)
  22.         {
  23.             full = true;
  24.             generation++;
  25.         }
  26.     }
  27.     void change_status(bool full_, cell c[][100], int row, int col) //
  28.     {
  29.         full = full_;
  30.         for (int q = -1; q < 2; q++)
  31.         {
  32.             for (int q2 = -1; q2 < 2; q2++)
  33.             {
  34.                 if (q == 0 && q2 == 0) //this element
  35.                     q2++;
  36.                 c[row + q][col + q2].NearCellStatusChanged(full_);
  37.             }
  38.  
  39.         }
  40.     }
  41.     void delete_check(cell cells[][100], int row, int col)
  42.     {
  43.         if (this->near < 2 || this->near > 3)
  44.             this->change_status(false, cells, row, col);
  45.     }
  46. };
  47.  
  48. int main()
  49. {
  50.     int row[100], col[100];
  51.     cell cells[100][100];
  52.     int i = 0;
  53.     for (i; cin; i++)
  54.     {
  55.         cout << "row: ";
  56.         cin >> row[i];
  57.         cout << endl;
  58.         cout << "col: ";
  59.         cin >> col[i];
  60.         cout << endl;
  61.         cells[row[i]][col[i]].change_status(true, cells, row[i], col[i]);
  62.     }
  63.     for (int q = 0; q < i; q++)
  64.         cells[row[q]][col[q]].delete_check(cells, row[q], col[q]);
  65.  
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement