fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int r,c;
  7. cin >> r >> c;
  8. vector<vector<int>> mat(r,vector<int>(c));
  9. vector<vector<int>> tmat(c,vector<int>(r));
  10. for(int i=0;i<r;i++){
  11. for(int j=0;j<c;j++){
  12. cin >> mat[i][j];
  13. tmat[j][i] = mat[i][j];
  14. }
  15. }
  16. cout << c << " " << r << "\n";
  17. for(int i=0;i<c;i++){
  18. for(int j=0;j<r;j++){
  19. cout << tmat[i][j] << " ";
  20. }
  21. cout << "\n";
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5472KB
stdin
3 4
1 2 3 4
5 6 7 8
9 10 11 12
stdout
4 3
1 5 9 
2 6 10 
3 7 11 
4 8 12