Advertisement
myloyo

6.3.9

Nov 28th, 2022 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <algorithm>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int n, t, m;
  11.     t = 0;
  12.     cin >> n >> m;
  13.     int **a = new int *[n];                    
  14.     for (int i = 0; i < n; i++) {
  15.         a[i] = new int[m];
  16.     }
  17.     for (int i = 0; i < n; i++) {
  18.         for (int j = 0; j < m; j++) {
  19.             cin >> *(*(a + i) + j);
  20.         }
  21.     }
  22.     int *b;
  23.     if (n % 2 == 0) {
  24.         for (int i = 0; i < n; i+=2) {
  25.             b = a[i];
  26.             a[i] = a[i+1];
  27.             a[i+1] = b;
  28.         }
  29.     }
  30.  
  31.     for (int i = 0; i < n; i++) {
  32.         for (int j = 0; j < m; j++) {
  33.             cout << a[i][j] << " ";
  34.         }
  35.         cout << endl;
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement