코딩테스트 문제풀이
-
[백준 1018] 체스판 다시 칠하기코딩테스트 문제풀이 2021. 12. 22. 14:49
문제 풀이 import java.util.Scanner; public class Main { private final static char WHITE = 'W'; private final static char BLACK = 'B'; private final static char[][] CORRECT_BOARD_BLACK = new char[][] { {BLACK, WHITE, BLACK, WHITE, BLACK, WHITE, BLACK, WHITE}, {WHITE, BLACK, WHITE, BLACK, WHITE, BLACK, WHITE, BLACK}, {BLACK, WHITE, BLACK, WHITE, BLACK, WHITE, BLACK, WHITE}, {WHITE, BLACK, WHITE, BLACK..
-
[백준 7568] 덩치코딩테스트 문제풀이 2021. 12. 22. 10:44
문제 풀이 import java.util.Scanner; class Main { /** * @param args */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] weight = new int[n]; int[] height = new int[n]; for (int i = 0; i < n; i++) { weight[i] = scan.nextInt(); height[i] = scan.nextInt(); } int[] answer = new int[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) {..
-
[백준 11729] 하노이 탑 이동 순서코딩테스트 문제풀이 2021. 12. 17. 15:35
문제 풀이 import java.util.Scanner; public class Main { public static int moveCount = 0; public static StringBuffer sb = new StringBuffer(); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.close(); hanoi(1,2,3,n); System.out.println(moveCount); System.out.println(sb.toString()); } public static void hanoi(int from, int middle, int..
-
[백준 17478] 재귀함수가 뭔가요?코딩테스트 문제풀이 2021. 12. 14. 14:27
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.close(); System.out.println("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다."); recursion(n, 0); } public static void recursion(int n, int recursionCount) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < recursionCount; i++) { sb.a..
-
[백준 10870] 피보나치 수 5코딩테스트 문제풀이 2021. 12. 14. 14:05
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); System.out.println(fibonacci(n)); } public static int fibonacci(int n) { if (n == 0) return 0; if (n == 1) return 1; return fibonacci(n-2) + fibonacci(n-1); } } 출처: https://www.acmicpc.net/problem/10870
-
[프로그래머스] 표 편집코딩테스트 문제풀이 2021. 10. 14. 23:20
문제 풀이 import java.util.*; class Solution { private static final char UP = 'U'; private static final char DOWN = 'D'; private static final char CUT = 'C'; private static final char RESTORE = 'Z'; public String solution(int n, int k, String[] cmd) { Stack deletedNode = new Stack(); Node root = new Node(0); Node currentNode = root; for (int i = 1; i < n; i++) { Node node = new Node(i); currentNode...
-
[프로그래머스] 다단계 칫솔 판매코딩테스트 문제풀이 2021. 10. 12. 23:27
문제 풀이 import java.util.*; class Solution { public int[] solution(String[] enroll, String[] referral, String[] seller, int[] amount) { int len = enroll.length; int[] answer = new int[len]; Map parentMap = new HashMap(); for (int i = 0; i < len; i++) { parentMap.put(enroll[i], referral[i]); } Map map = new HashMap(); for (int i = 0; i < seller.length; i++) { int sum = amount[i] * 100; divide(paren..