✅ 삼성 SW 역량테스트 개요
언어: C/C++, Java, Python (보통 C++이 유리하다는 얘기가 많지만, Java도 충분히 가능)
형식: 2문제, 총 3시간
유형: 구현, 시뮬레이션, 완전탐색 위주
난이도: 중상 (문제 자체가 어려운 게 아니라 조건 구현이 까다로움)
📌 자주 나오는 유형
시뮬레이션 문제
- 예) 청소 로봇, 캐릭터 이동, 블록 게임
- 시간 오래 걸리지만, 차근차근 구현하면 됨
DFS / BFS
- 예) 영역 구분, 최단 거리, 감시 카메라 등
- 재귀 구현 연습 필수
자료구조 활용
- Queue, Deque, Stack 등
- 예) 마트 줄서기, 뱀 게임 등
🛠 추천 준비 방식
기본기 탄탄히
- 입력 처리, 2차원 배열 다루기, 방향 배열 (dx, dy) 연습
- Java 기준 Scanner vs BufferedReader 차이도 알고 있어야 함
기출 문제 풀이
- 백준 "삼성 SW 역량 테스트 기출 문제" 태그: 바로가기
- SWEA 삼성 Expert 문제도 좋음
시간 분배 연습
- 보통 1번은 1시간 이내, 2번은 2시간 잡고 연습
📅 5일 단기 대비 커리큘럼 (Java 기준)
Day 1: 필수 구현 패턴 마스터
- 방향 배열 (dx, dy)로 이동 구현
- 2차원 배열 회전/복사 (deepcopy, rotate)
- Queue / Stack / Deque 연습 (Java에서 LinkedList, Deque)
- BufferedReader + StringTokenizer 익숙해지기 (입력 속도 중요)
- DFS / BFS 기본 구조 템플릿 암기
추천 문제 (백준)
Day 2: 시뮬레이션 실전 문제
- 상태 변화 구현 + 조건문 분기 처리 연습
- 2차원 배열 기반 시뮬레이션 구조 익히기
추천 기출
Day 3: DFS/BFS 집중 공략
- 탐색 깊이 조절, visited 배열 관리
- 여러 시작점에서의 탐색 구현 연습
추천 기출
Day 4: 실전 셋팅 + 모의 시험
- 오전: 실전 환경으로 2문제 3시간 풀기
- 오후: 실수 복기, 빠르게 구현 실패 이유 분석
- 시간 제한, 메모리 제한 감각 잡기
실전 모의 기출 추천
Day 5: 정리 + 마무리
- 자주 쓰는 코드 패턴 정리 (복붙 가능하게)
- 실수했던 포인트 한 눈에 보기
- 전날 무리하지 말고 코드만 가볍게 점검
✍️ 팁: 자주 쓰는 Java 구현 패턴 저장
// 방향 배열 (상하좌우)
int[] dx = {-1, 1, 0, 0};
int[] dy = {0, 0, -1, 1};
// BFS 기본 구조
Queue<int[]> q = new LinkedList<>();
boolean[][] visited = new boolean[N][M];
q.offer(new int[]{x, y});
visited[x][y] = true;
while (!q.isEmpty()) {
int[] now = q.poll();
int cx = now[0], cy = now[1];
for (int i = 0; i < 4; i++) {
int nx = cx + dx[i];
int ny = cy + dy[i];
// 범위 & 방문 체크
}
}
🔷 BFS (Breadth-First Search)
보통 최단거리, 레벨 탐색, 순차적 이동 문제에 사용
Queue 사용, while(!queue.isEmpty()) 구조
import java.util.*;
public class BFSExample {
static int N = 5, M = 5;
static int[][] map = new int[N][M];
static boolean[][] visited = new boolean[N][M];
static int[] dx = {-1, 1, 0, 0}; // 상하좌우
static int[] dy = {0, 0, -1, 1};
static void bfs(int x, int y) {
Queue<int[]> queue = new LinkedList<>();
queue.offer(new int[]{x, y});
visited[x][y] = true;
while (!queue.isEmpty()) {
int[] now = queue.poll();
int cx = now[0];
int cy = now[1];
for (int i = 0; i < 4; i++) {
int nx = cx + dx[i];
int ny = cy + dy[i];
// 범위 & 방문 체크
if (nx < 0 || ny < 0 || nx >= N || ny >= M) continue;
if (visited[nx][ny] || map[nx][ny] == 0) continue;
visited[nx][ny] = true;
queue.offer(new int[]{nx, ny});
}
}
}
}
🔷 DFS (Depth-First Search)
보통 재귀, 백트래킹, 모든 경우의 수를 다 따져야 하는 문제에 사용
public class DFSExample {
static int N = 5, M = 5;
static int[][] map = new int[N][M];
static boolean[][] visited = new boolean[N][M];
static int[] dx = {-1, 1, 0, 0};
static int[] dy = {0, 0, -1, 1};
static void dfs(int x, int y) {
visited[x][y] = true;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || ny < 0 || nx >= N || ny >= M) continue;
if (visited[nx][ny] || map[nx][ny] == 0) continue;
dfs(nx, ny);
}
}
}
📌 BFS vs DFS 차이 정리
항목 BFS DFS
사용 자료구조 | Queue (LinkedList) | 재귀 호출 (or Stack) |
사용 상황 | 최단 거리, 단계별 탐색 | 모든 경로 탐색, 조합/순열 |
특징 | 가까운 노드부터 탐색 | 깊게 들어가며 탐색 |
시간 복잡도 | O(N) | O(N) |
📌 1. 정렬 (Sorting)
✅ 기본 정렬 메서드
int[] arr = {5, 3, 2, 4, 1};
Arrays.sort(arr); // 오름차순 정렬
✅ 내림차순 정렬 (int 배열)
Integer[] arr = {5, 3, 2, 4, 1};
Arrays.sort(arr, Collections.reverseOrder());
✅ 2차원 배열 정렬 (Comparator)
int[][] arr = {
{1, 9},
{2, 8},
{3, 7}
};
// 첫 번째 요소 기준 오름차순 정렬
Arrays.sort(arr, Comparator.comparingInt(o -> o[0]));
// 두 번째 요소 기준 내림차순 정렬
Arrays.sort(arr, (a, b) -> Integer.compare(b[1], a[1]));
✅ 객체 정렬
class Node {
int x, y;
Node(int x, int y) {
this.x = x; this.y = y;
}
}
// x 기준 오름차순
List<Node> list = new ArrayList<>();
Collections.sort(list, Comparator.comparingInt(o -> o.x));
📌 2. 필수 자료구조
자료구조 클래스 주요 메서드 예시
배열 | int[] arr = new int[N]; | - |
리스트 | ArrayList<Integer> | add(), get(), size() |
큐 | Queue<Integer> | offer(), poll(), peek() |
덱 | Deque<Integer> | addFirst(), addLast(), pollFirst() |
스택 | Stack<Integer> | push(), pop(), peek() |
맵 | HashMap<Key, Value> | get(), put(), containsKey() |
집합 | HashSet<E> | add(), contains(), remove() |
우선순위큐 | PriorityQueue<Integer> | offer(), poll(), peek() |
💡 자주 쓰는 우선순위큐 (최솟값 기준)
PriorityQueue<Integer> pq = new PriorityQueue<>();
pq.offer(5);
int min = pq.poll(); // 가장 작은 값
💡 내림차순 우선순위큐
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
📌 3. 자주 쓰는 Java 메서드 모음
목적 메서드
배열 복사 | System.arraycopy() 또는 Arrays.copyOf() |
문자열 → 숫자 | Integer.parseInt(str) |
숫자 → 문자열 | String.valueOf(num) 또는 num + "" |
문자열 분리 | str.split(" "), new StringTokenizer() |
문자열 정렬 | char[] ch = str.toCharArray(); Arrays.sort(ch); |
배열 to 리스트 | Arrays.asList(arr) (주의: 기본형은 불가) |
리스트 정렬 | Collections.sort(list) |
2차원 배열 deep copy | array.clone()은 얕은 복사, 2중 for문으로 deep copy 필요 |
📌 4. 입출력 속도 향상
✅ 빠른 입력
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
✅ 빠른 출력
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
bw.write("출력할 문자열\n");
bw.flush(); // 출력 완료
'코딩테스트 > 코딩테스트(Java)' 카테고리의 다른 글
[코딩테스트] Java - 기본 점검: 자료구조 (0) | 2025.04.09 |
---|---|
[코딩테스트] Java - 패턴별 연습 문제 리스트 (0) | 2025.04.08 |
[코딩테스트] Java - 백트래킹 (0) | 2025.03.17 |
[코딩테스트] Java - 추천 문제 (0) | 2025.03.17 |
[코딩테스트] Java - 알고리즘 추천 문제 (0) | 2025.03.17 |