Advertisement
Bertran_rz

Караблики караблики

Sep 8th, 2021
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     srand(time(0));
  8.  
  9.     int const size = 10;
  10.  
  11.     int arr[size][size];
  12.  
  13.     int oneCount = 0;
  14.  
  15.     for (int i = 0; i < size; i++)
  16.     {
  17.         for (int j = 0; j < size; j++)
  18.         {
  19.             arr[i][j] = 0;
  20.             cout << arr[i][j] << " ";
  21.         }
  22.         cout << endl;
  23.     }
  24.     cout << endl;
  25.  
  26.     //Paint first level board
  27.  
  28.     for (int n = 0; n < 4; n++)
  29.     {
  30.         int x, y;
  31.         do
  32.         {
  33.             x = rand()%10;
  34.             y = rand()%10;
  35.  
  36.         } while (arr[x][y] != 0);
  37.  
  38.         for (int i = y - 1; i < y + 2; i++)
  39.         {
  40.             for (int j = x - 1; j < x + 2; j++)
  41.             {
  42.                 if (i >= 0 && j >= 0 && i < size && j < size)
  43.                     arr[j][i] = 2;
  44.             }
  45.         }
  46.  
  47.         arr[x][y] = 1;
  48.  
  49.     }
  50.  
  51.     for (int i = 0; i < size; i++)
  52.     {
  53.         for (int j = 0; j < size; j++)
  54.             cout << arr[i][j] << " ";
  55.         cout << endl;
  56.     }
  57.  
  58. }
  59.  
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement