From 46e81475de5f23fa1a5b0b14a6aadae3501772f8 Mon Sep 17 00:00:00 2001 From: sey2 <54762273+sey2@users.noreply.github.com> Date: Sun, 21 Aug 2022 20:17:29 +0900 Subject: [PATCH] =?UTF-8?q?=EC=84=B1=EA=B2=A9=20=EC=9C=A0=ED=98=95=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=20-=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20Teach=20?= =?UTF-8?q?Intership=20-=20level1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- programmers/Kbti.java | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 programmers/Kbti.java diff --git a/programmers/Kbti.java b/programmers/Kbti.java new file mode 100644 index 0000000..51fe883 --- /dev/null +++ b/programmers/Kbti.java @@ -0,0 +1,49 @@ +import java.io.IOException; +import java.util.HashMap; + + +class Solution { + char type [] = {'R', 'T', 'C', 'F', 'J', 'M', 'A', 'N'}; + public String solution(String[] survey, int[] choices) { + String answer = ""; + HashMap map = new HashMap<>(); + + for(int i=0; i< type.length; i++) map.put(type[i],0); + + for(int i=0; i< survey.length; i++){ + char a = survey[i].charAt(0); + char b = survey[i].charAt(1); + + int score = 4 - choices[i]; + + if(score > 0) map.put(a, map.getOrDefault(a,0) + score); + else if(score < 0) map.put(b, map.getOrDefault(b,0) + (score * -1)); + } + + for(int i=0; i b) answer += type[i]; + else if(a < b) answer += type[i+1]; + else if (a == b) answer += (type[i] > type[i+1]) ? type[i+1] : type[i]; + + i++; + + } + + return answer; + } +} + +public class Main { + + public static void main(String[] args) throws IOException { + + String ans = new Solution().solution(new String[]{"AN", "CF", "MJ", "RT", "NA"},new int[]{5,3,2,7,5}); + + System.out.println(ans); + + } + +}