题解 | #矩阵乘法#这算法题的难度等级谁评定的??
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int x = in.nextInt(); int y = in.nextInt(); int z = in.nextInt(); int[][] a = new int[x][y];//x行y列 int[][] b = new int[y][z];//y行z列 //读取矩阵输入 while (in.hasNextInt()) { for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { a[i][j] = in.nextInt(); } } for (int i = 0; i < y; i++) { for (int j = 0; j < z; j++) { b[i][j] = in.nextInt(); } } } int[][] res = new int[x][z]; for (int i = 0; i < x; i++) { for (int j = 0; j < z; j++) { res[i][j]=multy(a,b,i,j,y); System.out.print(res[i][j]+" "); if(j==z-1) System.out.println(); } } } public static int multy(int[][] a,int[][] b,int row,int col,int y){ int sum=0; for(int i=0;i<y;i++){ sum=sum+a[row][i]*b[i][col]; } return sum; } }
这种简单题评为中等,那种分苹果的困难题评为简单???脑子里一万个问号