Advertisement
awsmpshk

Untitled

Apr 10th, 2020
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T>
  6. T** createMas(int n, int m)
  7. {
  8.   T** mas = new T*[n];
  9.   for (int i = 0; i < n; ++i)
  10.   {
  11.     mas[i] = new T[m];
  12.     for (int j = 0; j < m; ++j)
  13.     {
  14.       cin >> mas[i][j];
  15.     }
  16.   }
  17.   return mas;
  18. }
  19.  
  20. template <typename T>
  21. int res(T** mas, int n, int m, T a, T b)
  22. {
  23.   int cnt = 0;
  24.   for (int i = 0; i < n; ++i)
  25.   {
  26.     for (int j = 0; j < m; ++j)
  27.     {
  28.       if (mas[i][j] < a || mas[i][j] > b) {
  29.         cnt++;
  30.       }
  31.     }
  32.   }
  33.   return cnt;
  34. }
  35.  
  36. template <typename T>
  37. void deleteMas(T** mas, int n, int m)
  38. {
  39.   for (int i = 0; i < n; ++i)
  40.   {
  41.     delete[] mas[i];
  42.   }
  43.   delete[] mas;
  44. }
  45.  
  46. int main()
  47. {
  48.   int n, m;
  49.   cin >> n >> m;
  50.  
  51.   int** mas = createMas<int>(n, m);
  52.  
  53.   int a, b;
  54.   cin >> a >> b;
  55.  
  56.   cout << res(mas, n, m, a, b) << endl;
  57.   deleteMas(mas, n, m);
  58.  
  59.   return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement