Advertisement
Guest User

Untitled

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