fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int m, n;
  6. cin>>m>>n;
  7. vector<vector<int>> arr(m,vector<int>(n,0));
  8. for (int i=0; i<m; i++){
  9. for (int j=0; j<n; j++)
  10. cin>>arr[i][j];
  11. }
  12.  
  13. // for (int i=0; i<m; i++){
  14. // for (int j=0; j<n; j++){
  15. // if (i>j) swap (arr[i][j], arr[j][i]);
  16. // }
  17. // }
  18.  
  19. for (int i=0; i<m; i++){
  20. for (int j=0; j<n; j++){
  21. if (i&1==1)
  22. cout<<arr[i][n-1-j]<<" ";
  23. else
  24. cout<<arr[i][j]<<" ";
  25. }
  26. // cout<<endl;
  27. }
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5320KB
stdin
3 3

2 3 4 
5 6 7
8 9 0
stdout
2 3 4 7 6 5 8 9 0