Advertisement
awsmpshk

Untitled

Apr 9th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 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. void res(T** mas, int n, int m, T a, T b)
  22. {
  23.   for (int i = 0; i < n; ++i)
  24.   {
  25.     for (int j = 0; j < m; ++j)
  26.     {
  27.       if (mas[i][j] > a && mas[i][j] < b) {
  28.         cout << mas[i][j] << " ";
  29.       }
  30.     }
  31.     cout << endl;
  32.   }
  33. }
  34.  
  35. template <typename T>
  36. void deleteMas(T** mas, int n, int m)
  37. {
  38.   for (int i = 0; i < n; ++i)
  39.   {
  40.     delete[] mas[i];
  41.   }
  42.   delete[] mas;
  43. }
  44.  
  45. int main()
  46. {
  47.   int n, m;
  48.   cin >> n >> m;
  49.  
  50.   int** mas = createMas<int>(n, m);
  51.  
  52.   int a, b;
  53.   cin >> a >> b;
  54.  
  55.   res(mas, n, m, a, b);
  56.   deleteMas(mas, n, m);
  57.  
  58.   return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement