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