MapleStory Finger Point

๐Ÿƒ‍โ™€๏ธprogrammers/Java

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] Lv.1 ์„ฑ๊ฒฉ ์œ ํ˜• ๊ฒ€์‚ฌํ•˜๊ธฐ

HYEJU01 2025. 5. 5. 06:51
๋ฌธ์ œ : Lv.1 ์„ฑ๊ฒฉ ์œ ํ˜• ๊ฒ€์‚ฌํ•˜๊ธฐ https://school.programmers.co.kr/learn/courses/30/lessons/118666
์–ธ์–ด : JAVA
์ฒด๊ฐ Level : โ˜… โ˜† โ˜†
Review: map ์ด๋ผ๋Š” ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์ž˜ ํ™œ์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ

 

 

๐Ÿ’ก map ์—๋Š” ๊ณ ์ •๋˜์–ด์žˆ๋Š” ์„ฑ๊ฒฉ์œ ํ˜• 8๊ฐ€์ง€๋ฅผ ๋„ฃ์–ด์ฃผ๊ณ 

map2 ์—์„œ๋Š” ์„ ํƒ์ง€๋ณ„ ์นด์šดํŒ… ๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค

์ด๋•Œ map ์€ ์ˆœ์„œ๋Œ€๋กœ ๋„ฃ์–ด๋„ ์ˆœ์„œ ๋ณด์žฅ์ด ์•ˆ๋œ๋‹ค

TreeMap ์„ ์‚ฌ์šฉํ•˜๋ฉด ์ •๋ ฌ์€ ๋˜์ง€๋งŒ ์„ฑ๊ฒฉ ์œ ํ˜•์˜ ๋Œ€์นญ์— ๋งž๊ฒŒ ๋น„๊ตํ•ด์•ผํ•˜๊ธฐ๋•Œ๋ฌธ์— ๊ตณ์ด ?

๊ทธ๋ž˜์„œ  list ์— ๋Œ€์นญ๋˜๋Š” ์„ฑ๊ฒฉ์œ ํ˜•์„ ๋„ฃ์–ด์„œ ๋น„๊ตํ•ด์คฌ๋‹ค.

import java.util.*;

class Solution {
    public String solution(String[] survey, int[] choices) {
        String answer = "";
        
        Map<Character, Integer> map = new HashMap<>();
        
        map.put('R',0); map.put('C',0); map.put('J',0); map.put('A',0);
        map.put('T',0); map.put('F',0); map.put('M',0); map.put('N',0);
        
        Map<Integer, Integer> map2 = new HashMap<>();
            
        map2.put(1,-3); map2.put(2,-2); map2.put(3,-1); 
        map2.put(4,0);
        map2.put(5,1); map2.put(6,2); map2.put(7,3); 
        
        int i = 0;
        int hap = 0;
        
        for(int c : choices){
            if(map2.get(c) < 0){
                hap = map.get(survey[i].charAt(0)) + (map2.get(c) * (-1));
                map.put(survey[i].charAt(0), hap);
            }else{
                hap = map.get(survey[i].charAt(1)) + map2.get(c);
                map.put(survey[i].charAt(1), hap);
            }
            
            i++;
            hap = 0;
        }
        

        String[] list = {"RT", "CF", "JM", "AN"};

        
        for (int j = 0; j < list.length; j++){
          if (map.get(list[j].charAt(0)) > map.get(list[j].charAt(1))){
                answer += list[j].charAt(0);
            }else if (map.get(list[j].charAt(0)) < map.get(list[j].charAt(1))){
                answer += list[j].charAt(1);

            }else {
                if ((int)list[j].charAt(0) > (int)list[j].charAt(1)){
                    answer += list[j].charAt(1);
                }else {
                    answer += list[j].charAt(0);
                }
            }
        }
      


        return answer;
    }
}