-
[백준-2740] 행렬곱셈 - Java공부/백준 2023. 7. 13. 22:37728x90
https://www.acmicpc.net/problem/2740
백준 2740번 행렬곱셈 자바 풀이
난이도: S5
코드
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n=scanner.nextInt(); int m= scanner.nextInt(); int A[][]=new int[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ A[i][j]=scanner.nextInt(); } } m=scanner.nextInt(); int k=scanner.nextInt(); int B[][]=new int[m][k]; for(int i=0;i<m;i++){ for(int j=0;j<k;j++){ B[i][j]=scanner.nextInt(); } } int C[][]=new int[n][k]; for(int i=0;i<n;i++){ for(int j=0;j<k;j++){ for(int l=0;l<m;l++){ C[i][j]+=A[i][l]*B[l][j]; } } } for(int i=0;i<n;i++){ for(int j=0;j<k;j++){ System.out.print(C[i][j]+" "); } System.out.println(); } } }
728x90반응형'공부 > 백준' 카테고리의 다른 글
[백준-18110] solved.ac - Java (0) 2024.03.10 [백준-10171] 개 - Text (0) 2023.04.23 [백준-10171] 고양이 - Text (0) 2023.04.23 [백준-11382] 꼬마 정민 - Java (0) 2023.04.23 [백준-2588] 곱셈 - C++ (0) 2023.04.23