10: matrix transpose, 10 Matrix
10: matrix transpose
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Input A matrix A of n rows and m columns and output its transpose.
-
Input
-
The first line contains two integers n and m, indicating the number of rows and columns of matrix. 1 <= n <= 100, 1 <= m <=.
In the next n rows, each row has m integers, indicating the elements of matrix. Two Adjacent integers are separated by a single space. Each element ranges from 1 ~ In the range of 1000.
-
Output
-
M row, n integers in each row, is the transpose of matrix. Two Adjacent integers are separated by a single space.
-
Sample Input
-
3 31 2 34 5 67 8 9
-
Sample output
-
1 4 72 5 83 6 9
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 int a[10001][10001]; 6 int main() 7 { 8 int n,m; 9 cin>>n>>m;10 for(int i=1;i<=n;i++)11 {12 for(int j=1;j<=m;j++)13 {14 cin>>a[i][j];15 }16 }17 int j=1;18 if(n==1)19 {20 for(int i=1;i<=n;i++)21 {22 for(int j=1;j<=m;j++)23 {24 cout<<a[i][j];25 cout<<endl;26 }27 }28 return 0;29 }30 31 for(int i=1;i<=n;i++)32 {33 34 while(j<=m)35 {36 cout<<a[i][j]<<" ";37 i++;38 if(i==n)39 {40 cout<<a[i][j]<<" ";41 cout<<endl;42 j++;43 i=1;44 }45 46 } 47 48 }49 return 0;50 }