-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain_2.java
More file actions
53 lines (52 loc) · 1.8 KB
/
Copy pathMain_2.java
File metadata and controls
53 lines (52 loc) · 1.8 KB
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
47
48
49
50
51
52
53
import java.util.Objects;
import java.util.Scanner;
public class Main_2 { // 2022년 시도상업경진대회 비지니스 프로그래밍 2번 문제
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
String[][] result = new String[a][b];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
result[i][j] = "0";
}
}
int c = sc.nextInt();
for (int i = 0; i < c; i++) {
String xy = sc.next();
int x = xy.charAt(1) - '0';
int y = xy.charAt(3) - '0';
for (int k = 0; k < a; k++) {
for (int d = 0; d < b; d++) {
if (k == x && d == y) {
result[d][k] = "X";
}
}
}
}
int[] dx = { -1, 0, 1, 0 , -1, 1,-1, 1};
int[] dy = { 0, 1, 0 ,-1, -1, 1, 1, -1};
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
int sum = 0;
if(!Objects.equals(result[i][j], "X")){
for (int k = 0; k < 8; k++) {
if ((i + dx[k]) >= 0 && (j + dy[k]) >= 0 && (i + dx[k]) <= a-1 && (j + dy[k]) <= b-1) {
if(Objects.equals(result[i + dx[k]][j + dy[k]], "X")){
sum++;
}
}
}
result[i][j] = String.valueOf(sum);
}
}
}
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
System.out.print(result[i][j]);
}
System.out.println();
}
sc.close();
}
}