1
|
import java.util.Scanner;
public class solution_d2_1959 { public static void main(String[] args) { // 1959. 두개의 숫자열 Scanner sc = new Scanner(System.in); // 반복 횟수 int chaces = sc.nextInt(); // 반복 횟수만큼 반복 for (int i = 0; i < chaces; i++) { int max=0; int total; // 길이 입력 int N = sc.nextInt(); int M = sc.nextInt(); // 입력한 길이로 배열 생성 int[] A = new int[N]; int[] B = new int[M]; // 각 배열에 원소 직접입력 for (int j = 0; j < N; j++) { A[j] = sc.nextInt(); } for (int k = 0; k < M; k++) { B[k] = sc.nextInt(); } int len=Math.abs(N-M); //A배열이 B배열보다 큰 경우 if (A.length > B.length) { for (int x = 0; x < len + 1; x++) { total=0; for (int z=0; z<B.length; z++) { total+=A[z+x]*B[z]; } if (max<total) max=total; } } //B배열이 A배열 보드 큰 경우 else if (B.length > A.length) { for (int x = 0; x < len + 1; x++) { total=0; for (int z=0; z<A.length; z++) { total+=A[z]*B[z+x]; } if (max<total) max=total; } } //길이가 같은 경우 else { total=0; for (int z=0; z<N; z++) { total+=A[z]*B[z]; } max=total; } System.out.println("#"+(i+1)+" "+max); } } } |
cs |
'Algorithm > SWEA' 카테고리의 다른 글
[SWEA] 2001: 파리퇴치 (JAVA) (0) | 2022.07.05 |
---|---|
[SWEA] 1979: 어디에 단어가 들어갈수 있을까? (JAVA) (0) | 2022.07.05 |
[SWEA] 2025: N줄 덧셈 (python) (0) | 2022.07.04 |
[SWEA] 2019: 더블더블 (python) (0) | 2022.07.04 |
[SWEA] 1938: 아주 간단한계산기 (python) (0) | 2022.07.04 |