Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include "cmath"
  2. #include <iostream>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. bool func(float a, float b, float c, float d, float S)
  7. {
  8.     if ((a + b + c + d) < S) { return true; }
  9.     else { return false; }
  10. }
  11.  
  12. int main()
  13. {
  14.     srand(time(NULL));
  15.  
  16.     int n, m;
  17.     float S;
  18.  
  19.     cout << "Enter n and m" << endl;
  20.     cin >> n >> m;
  21.     cout << "Enter S" << endl;
  22.     cin >> S;
  23.  
  24.     float **a = new float*[n];
  25.     for (int i = 0; i < n; i++)
  26.         a[i] = new float;
  27.     for (int i = 0; i < n; i++)
  28.         for (int j = 0; j < m; j++)
  29.             a[i][j] = rand()%500;
  30.  
  31.     cout << "Start array:" << endl;
  32.     for (int i = 0; i < n; i++)
  33.     {
  34.         for (int j = 0; j < m; j++)
  35.             cout << a[i][j] << " ";
  36.         cout << endl;
  37.     }
  38.    
  39.  
  40.     bool **b = new bool*[n];
  41.     for (int i = 0; i < n; i++)
  42.         b[i] = new bool;
  43.     for (int i = 0; i < n; i++)
  44.         for (int j = 0; j < m; j++)
  45.             b[i][j] = false;
  46.  
  47.     for (int i = 0; i < n; i++)
  48.         for (int j = 0; j < m; j++)
  49.             if ((i == 0) || (i == (n - 1)) || (j == 0) || (j == (m - 1)))
  50.             {
  51.                 if ((i == 0) && (j == 0)) { if ((a[i + 1][j] + a[i][j + 1]) < S) b[i][j] = true; }
  52.                 else if ((i == 0) && (j == (m - 1))) { if ((a[i + 1][j] + a[i][j - 1]) < S) b[i][j] = true; }
  53.                 else if ((i == (n - 1)) && (j == 0)) { if ((a[i - 1][j] + a[i][j + 1]) < S) b[i][j] = true; }
  54.                 else if ((i == (n - 1)) && (j == (m - 1))) { if ((a[i - 1][j] + a[i][j - 1]) < S) b[i][j] = true; }
  55.                 else if (i == 0) { if ((a[i + 1][j] + a[i][j - 1] + a[i][j + 1]) < S) b[i][j] = true; }
  56.                 else if (j == 0) { if ((a[i - 1][j] + a[i + 1][j] + a[i][j + 1]) < S) b[i][j] = true; }
  57.                 else if (i == (n - 1)) { if ((a[i - 1][j] + a[i][j - 1] + a[i][j + 1]) < S) b[i][j] = true; }
  58.                 else if (j == (m - 1)) { if ((a[i - 1][j] + a[i][j - 1] + a[i + 1][j]) < S) b[i][j] = true; }
  59.             }
  60.             else { b[i][j] = func(a[i - 1][j], a[i + 1][j], a[i][j - 1], a[i][j + 1], S); }
  61.  
  62.     cout << "Resulting array:" << endl;
  63.     for (int i = 0; i < n; i++)
  64.     {
  65.         for (int j = 0; j < m; j++)
  66.             cout << b[i][j] << " ";
  67.         cout << endl;
  68.     }
  69.    
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement