전체 글
-
[백준 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..
-
[백준 1931] 회의실 배정 - 그리디 알고리즘코딩테스트 문제풀이 2021. 10. 12. 23:24
문제 풀이 import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int count = scanner.nextInt(); int[][] conversations = new int[count][2]; for (int i = 0; i < count; i++) { conversations[i][0] = scanner.nextInt(); conversations[i][1] = scanner.nextInt(); } scanner.close(); ..
-
[면접스터디 1주차] JAVA/WEB/Spring그 외/면접준비 2021. 10. 11. 17:19
JAVA 1. 추상클래스와 인터페이스의 차이 추상클래스: 추상메소드가 1개이상 존재하며 abstract로 정의된 클래스. 다중상속 불가 및 extends를 통해 상속받음. 생성자를 가지며 객체화 가능. 인터페이스: 상수와 추상메소드의 집합. 다중상속 가능 및 implements를 통해 상속받음. 생성자X 객체화X. Java8 버전부터 Default 추상메소드 선언 및 초기화 가능 2. Exception의 종류 Error: 메모리 부족, 스택오버플로우 등과 같이 발생하게 되면 복구할 수 없는 심각한 오류 Checked Exception: 컴파일 시 검사하는 예외. 개발자가 반드시 예외처리를 해야하며 그렇지 않으면 컴파일에러 발생. IOException, SQL Exception 등 Unchekd Excep..
-
[백준 1920] 수찾기 - 이분탐색코딩테스트 문제풀이 2021. 10. 7. 22:42
문제 풀이 import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] src = new int[n]; for (int i = 0; i < n; i++) { src[i] = scanner.nextInt(); } int m = scanner.nextInt(); int[] target = new int[m]; for (int i = 0; i < m; i++) { target[i] = scanner.nextInt(); } scanner.cl..