코딩테스트 문제풀이
-
[백준 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(); ..
-
[백준 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..
-
[프로그래머스] 야근지수코딩테스트 문제풀이 2021. 10. 6. 22:51
문제 풀이 import java.util.*; class Solution { public long solution(int n, int[] works) { long answer = 0; PriorityQueue pqWorks = new PriorityQueue(Collections.reverseOrder()); int sum = 0; for (int work : works) { sum += work; pqWorks.offer(work); } if (n > sum) return answer; while (n > 0) { Integer maxWork = pqWorks.poll(); n--; pqWorks.offer(maxWork - 1); } answer = getOvertimeWorkingRate(pqWor..
-
[백준 2798] 블랙잭코딩테스트 문제풀이 2021. 10. 6. 22:21
문제 풀이 import java.util.Scanner; public class Main { static int max = 0; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int m = scanner.nextInt(); int[] cards = new int[n]; for (int i = 0; i < n; i ++) { cards[i] = scanner.nextInt(); } scanner.close(); boolean[] used = new boolean[n]; permutation(cards, new int[3], 0, used, m); System..
-
[프로그래머스] 베스트앨범 - 해시코딩테스트 문제풀이 2021. 10. 2. 16:25
문제 풀이 import java.util.*; class Solution { public int[] solution(String[] genres, int[] plays) { int[] answer = {}; List answerList = new ArrayList(); Map genresPlayCount = new HashMap(); for (int i = 0; i < genres.length; i++) { String genre = genres[i]; int playCount = plays[i]; genresPlayCount.put(genre, genresPlayCount.getOrDefault(genre, 0) + playCount); } List genreRankList = new ArrayList..
-
[백준 11279] 최대힙 - 우선순위 큐코딩테스트 문제풀이 2021. 10. 2. 15:01
문제 풀이 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.PriorityQueue; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PriorityQueue heap = new PriorityQueue((o1, o2) -> o2 - o1); int N = Integer.parseInt(br.r..
-
[프로그래머스] 소수 찾기 - 완전탐색코딩테스트 문제풀이 2021. 10. 2. 00:18
문제 풀이 import java.util.*; class Solution { public int solution(String numbers) { int answer = 0; Set allNumbers = new HashSet(); getAllNumbers(allNumbers, numbers, ""); for (Integer num : allNumbers) { if (isPrime(num)) answer++; } return answer; } public void getAllNumbers(Set allNumbers, String numbers, String numStr) { if (!numStr.equals("")) allNumbers.add(Integer.parseInt(numStr)); if (numb..
-
[백준 2231] 분해합코딩테스트 문제풀이 2021. 9. 22. 14:06
문제 풀이 package com.allwon.skylife.tcs; import java.util.ArrayList; import java.util.Arrays; import java.util.List; 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 answer = 0; for (int i = 1; i < n; i++) { int sum = 0; sum += i; String iString = String.valueOf(i); for (int j = 0;..