Coding Test
-
프로그래머스 (Level 3) - 네트워크Coding Test/Coding Test 문제 풀이 2022. 1. 26. 17:27
문제 설명 코딩테스트 연습 - 네트워크 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있 programmers.co.kr 풀이 연결된 컴퓨터에 대한 정보로 그래프를 생성한 후 DFS 또는 BFS 알고리즘을 사용해서 그래프 내 네트워크의 개수를 구하면 되는 문제이다. /* 그래프의 각 노드에 대한 정보를 정의 */ class Node { int data; // 노드의 번호 ArrayList adjacents; // 인접한 노드들 boolean visited; // 방문 여부 Node(int data) { this.data = data; this.adjacents = ..
-
프로그래머스 (Level 2) - 프린터Coding Test/Coding Test 문제 풀이 2022. 1. 25. 18:49
문제 설명 코딩테스트 연습 - 프린터 일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요한 문서가 나중에 인쇄될 수 있습니다. 이런 문제를 보완하기 위해 중요도가 높은 문서를 먼저 인쇄하는 프린 programmers.co.kr 풀이 1. 인쇄 대기목록의 가장 앞에 있는 문서(J)를 대기목록에서 꺼냅니다. 2. 나머지 인쇄 대기목록에서 J보다 중요도가 높은 문서가 한 개라도 존재하면 J를 대기목록의 가장 마지막에 넣습니다. 3. 그렇지 않으면 J를 인쇄합니다. 지문에 주어진 위의 조건에 따라 코드를 구현하면 되는 문제이다. 우선, 인쇄물의 정보를 정의한 클래스를 생성해주었다. 각 인쇄물은 중요도와 번호에 대한 정보를 가지게 된다. 가장 앞에 있는 문서를 하나씩 탐색하기 위해서 큐..
-
프로그래머스 (Level 2) - 위장Coding Test/Coding Test 문제 풀이 2022. 1. 6. 14:12
문제 설명 코딩테스트 연습 - 위장 programmers.co.kr 풀이 여러 종류의 의상이 있고 각 종류별로 1개 이상의 옷을 입을 수 있다면, 몇 가지 의상의 조합이 가능한가를 구하는 문제이다. 종류 별로 의상의 개수를 구하고, 경우의 수를 구하는 방식으로 문제를 해결하였다. 문제의 첫 번째 예시를 아래 표와 같이 표현이 가능하다. headgear와 관련된 의상은 총 2개가 있으니 총 3가지의 경우의 수가 있다. ㆍ 1번을 입는다. ㆍ 2번을 입는다. ㆍ headgear와 관련된 의상을 입지 않는다. eyewear와 관련된 의상은 총 2개가 있으니 총 2가지의 경우의 수가 있다. ㆍ 1번을 입는다. ㆍ eyewear와 관련된 의상을 입지 않는다. 최종적으로 3 x 2가지의 경우의 수인 6가지가 존재하..
-
프로그래머스 (Level 2) - 타겟 넘버Coding Test/Coding Test 문제 풀이 2022. 1. 5. 15:32
문제 설명 코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 있습니다. -1+1+1+1+1 = 3 +1-1+1+1+ programmers.co.kr 풀이 n개의 음이 아닌 정수가 주어졌을 때, 주어진 수를 더하거나 빼서 타겟 넘버로 만들 수 있는 방법의 수를 반환하는 문제이다. 깊이 우선 탐색을 활용해서 더하기, 빼기 연산으로 만들 수 모든 조합을 구성하였다. 조합을 구성한 후 주어진 numbers 배열 내 숫자들을 활용하여 결괏값을 만든다. 결괏값이 매개변수로 주어진 타겟 넘버와 일치할 경우 카운트를 해주는 방식으로 문제를 해결하였다. 전체 ..
-
프로그래머스 (Level 1) - 체육복Coding Test/Coding Test 문제 풀이 2022. 1. 4. 13:00
문제 설명 코딩테스트 연습 - 체육복 점심시간에 도둑이 들어, 일부 학생이 체육복을 도난당했습니다. 다행히 여벌 체육복이 있는 학생이 이들에게 체육복을 빌려주려 합니다. 학생들의 번호는 체격 순으로 매겨져 있어, 바로 앞번 programmers.co.kr 풀이 학생들이 가지고 있는 체육복의 개수를 배열 내에 저장하고, 배열을 하나씩 탐색하면서 체육복을 가지고 있지 않은 학생일 경우 앞, 뒤 학생에 빌릴 수 있는지 검사를 하며 문제를 해결하였다. 우선, 체육복의 개수를 저장할 배열 person을 선언한다. person 배열을 선언한 후 배열 내 모든 원소를 1로 초기화한다. 이후, lost 배열 내의 원소를 탐색하며, 해당 원소에 대한 person의 값을 1씩 감소시키고, reserve 배열 내의 원소를 ..
-
프로그래머스 (Level 2) - 소수 찾기Coding Test/Coding Test 문제 풀이 2022. 1. 3. 15:07
문제 설명 코딩테스트 연습 - 소수 찾기 한자리 숫자가 적힌 종이 조각이 흩어져있습니다. 흩어진 종이 조각을 붙여 소수를 몇 개 만들 수 있는지 알아내려 합니다. 각 종이 조각에 적힌 숫자가 적힌 문자열 numbers가 주어졌을 때, 종이 programmers.co.kr 풀이 문자열 numbers가 주어졌을 때, 각 숫자로 만들 수 있는 소수가 몇 개인지 반환하는 문제이다. 가장 간단한 방법으로 각 숫자로 만들 수 있는 모든 조합을 만든 후, 해당 숫자가 소수인 경우를 카운트하는 완전 탐색의 방식으로 문제를 해결하였다. 풀이 방법은 다음과 같다. 1. 백트래킹 방식을 사용해서 각 숫자로 만들 수 있는 모든 조합을 만든다. 2. 각 숫자가 소수인지 판별한다. 3. 해당 숫자가 소수인 경우 HashMap 자..