From ce794b08443ab4a9884836662f5050a82a57b02f Mon Sep 17 00:00:00 2001 From: Moonsu Kang <85223787+MoonsuKang@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:54:03 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=EB=AA=A8=EC=9D=98=EA=B3=A0=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lv.1/week6_1.java | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Lv.1/week6_1.java diff --git a/Lv.1/week6_1.java b/Lv.1/week6_1.java new file mode 100644 index 0000000..938a887 --- /dev/null +++ b/Lv.1/week6_1.java @@ -0,0 +1,40 @@ +import java.util.*; + +class Solution { + public int[] solution(int[] answers) { + int[] pattern1 = {1, 2, 3, 4, 5}; // 5 + int[] pattern2 = {2, 1, 2, 3, 2, 4, 2, 5,}; // 8 + int[] pattern3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5,};// 10 + // 맞힌 문제 수를 저장 + int[] scores = new int[3]; + + for(int i=0; i < answers.length; i++) { + if(answers[i] == pattern1[i%pattern1.length]) { + scores[0]++; + } + if(answers[i] == pattern2[i%pattern2.length]) { + scores[1]++; + } + if(answers[i] == pattern3[i%pattern3.length]) { + scores[2]++; + } + } + + int maxScore = Math.max(scores[0], Math.max(scores[1],scores[2])); + + List result = new ArrayList<>(); + for(int i=0; i < scores.length; i++){ + if(scores[i] == maxScore) { + result.add(i+1); + } + } + + // System.out.println(maxScore); + + return result.stream().mapToInt(i -> i).toArray(); + } +} + +// 1번 : 1, 2, 3, 4, 5 +// 2번 : 2, 1, 2, 3, 2, 4, 2, 5, +// 3번 : 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, From 6dafd0c40ddb11216b57af415841788fe25c19b1 Mon Sep 17 00:00:00 2001 From: Moonsu Kang <85223787+MoonsuKang@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:54:58 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EB=8B=AC=EB=A6=AC=EA=B8=B0=20=EA=B2=BD?= =?UTF-8?q?=EC=A3=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lv.1/week6_2.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Lv.1/week6_2.java diff --git a/Lv.1/week6_2.java b/Lv.1/week6_2.java new file mode 100644 index 0000000..1948424 --- /dev/null +++ b/Lv.1/week6_2.java @@ -0,0 +1,30 @@ +import java.util.*; + +class Solution { + public String[] solution(String[] players, String[] callings) { + HashMap playerMap = new HashMap<>(); + + for(int i=0; i < players.length; i++){ + playerMap.put(players[i], i); // 인덱스가 키 벨류가 이름 + } + + // 추월 처리 + for(String calling: callings) { + //추월한 선수 순위 + int currentIndex = playerMap.get(calling); + // 자기 앞에 선수를 추월 + int prevIndex = currentIndex - 1; + + String prevPlayer = players[prevIndex]; // 앞에 있던 선수 + players[prevIndex] = calling; // 추월한 선수가 앞자리로 + players[currentIndex] = prevPlayer; // 앞에 있던 선수는 한 칸 뒤로 + + // 선수 위치를 바꿔 + playerMap.put(calling, prevIndex); + playerMap.put(prevPlayer, currentIndex); + + } + + return players; + } +} From 64a6fdd87969cd40dc4c4aa5ef7d4ee7f60ca1eb Mon Sep 17 00:00:00 2001 From: Moonsu Kang <85223787+MoonsuKang@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:55:22 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EC=B9=B4=ED=8E=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lv.2/week6_3.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Lv.2/week6_3.java diff --git a/Lv.2/week6_3.java b/Lv.2/week6_3.java new file mode 100644 index 0000000..087dcb3 --- /dev/null +++ b/Lv.2/week6_3.java @@ -0,0 +1,24 @@ +class Solution { + public int[] solution(int brown, int yellow) { + int[] answer = {}; + + int total = brown + yellow; // 12 + // 가능한 세로 길이 (height)는 1부터 시작 + for(int height =1; height <= total; height++){ //1~12 + // 가로 길이 (width)는 전체 격자 수를 height로 나눈 값 + if (total % height == 0) { // 12 / h + int width = total / height; + + // 가로가 세로보다 크거나 같아야 한다는 조건 + if(width >= height) { + // 갈색 격자의 개수를 만족하는지 체크 + int border = (width*2) + (height*2) -4; + if(border == brown) { + return new int[]{width, height}; + } + } + } + } + return new int[]{}; + } +}