코드
static class Fish {
int x, y;
Fish(int x, int y) {
this.x = x; // x좌표
this.y = y; // y좌표
}
}
ArrayList<Fish>[][] map = new ArrayList[4][4];
ArrayList<Fish> list = new ArrayList<>();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
map[i][j] = new ArrayList<>();
}
}
for (int i = 0; i < M; i++) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
list.add(new Fish(x, y));
}
설명
이차원 배열의 각 요소는 Fish 객체를 저장하는 ArrayList임
이로써 각 위치마다 여러마리의 물고기가 존재하는 것을 구현할 수 있음 (한 칸에 요소 여러개)