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