728x90
반응형
https://www.acmicpc.net/problem/2167
2167번: 2차원 배열의 합
첫째 줄에 배열의 크기 N, M(1 ≤ N, M ≤ 300)이 주어진다. 다음 N개의 줄에는 M개의 정수로 배열이 주어진다. 배열에 포함되어 있는 수는 절댓값이 10,000보다 작거나 같은 정수이다. 그 다음 줄에는
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import java.util.Scanner;
public class Main {
public static int n, m, oper, sum = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
int[][] arr = new int[n + 1][m + 1];
for (int k = 1; k <= n; k++) {
for (int l = 1; l <= m; l++) {
arr[k][l] = sc.nextInt();
}
}
oper = sc.nextInt();
for (int k = 0; k < oper; k++) {
sum = 0;
int i = sc.nextInt();
int j = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
for (int i2 = i; i2 <= x; i2++) {
for (int j2 = j; j2 <= y; j2++) {
sum += arr[i2][j2];
}
}
System.out.println(sum);
}
}
}
|
cs |
728x90
반응형
'Java > 백준' 카테고리의 다른 글
[java 백준] 브론즈 3/ 1267번 핸드폰 요금 (1) | 2021.07.18 |
---|---|
[java 백준] 브론즈 1/ 1157번 단어공부 (0) | 2021.07.18 |
[java 백준] 브론즈 3/ 2783번 삼각 김밥 (0) | 2021.07.17 |
[java 백준] 브론즈 2/1568번 새 (0) | 2021.07.17 |
[백준 java] 브론즈3/4493번 가위 바위 보? (0) | 2021.07.14 |
댓글