Resource constraints
Time limit: 1.0s Memory Limit: 256.0MB
[Problem Description]
Given an n × m matrix multiplication, seeking its transpose. Wherein the 1≤n≤20,1≤m≤20, each matrix element represents the integer type (4 bytes) range.
[Input format
of the first row two integers n and m;
from the second row, each row integers m, a total of n lines, n × m matrix represents. They are separated by a space between the data.
[Output format]
A total of m lines of n integers, separated by a space between the data representing the transposed matrix.
Sample input
2. 4
34 is 76 -54. 7
-4. 5. 9 23 is
sample output
34 is -4
76. 5
-54 23 is
. 7. 9
import java.util.Scanner;
public class 矩阵转置 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner abc=new Scanner(System.in);
int a=abc.nextInt();
int b=abc.nextInt();
int[][] c=new int[a][b];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
c[i][j]=abc.nextInt();
}
}
for (int i = 0; i <b; i++) {
for (int j = 0; j<a; j++) {
System.out.print(c[j][i]+" ");
}
System.out.println();
}
}
}