문제

import java.util.HashMap;
import java.util.Map;

class Solution {
	Map<Character, Integer> surveyMap = new HashMap<Character, Integer>();
	int[] scoreArr = {3,2,1,0,1,2,3};
	String[] survey;
	int[] choices;
	
	public String solution(String[] survey, int[] choices) {
    	this.survey = survey;
    	this.choices = choices;
    	
    	for(char key : "RTCFJMAN".toCharArray()) {
    		surveyMap.put(key, 0);
    	}
    	
    	for(int i=0; i<survey.length;i++) {
    		String tmp = survey[i];
    		char l = tmp.charAt(0);
    		char r = tmp.charAt(1);
			calculate(l,r,i);
    	}
    	
    	StringBuilder sb =new StringBuilder();
    	sb.append( sum('R','T')>=0?"R" : "T");
    	sb.append( sum('C','F')>=0?"C" : "F");
    	sb.append( sum('J','M')>=0?"J" : "M");
    	sb.append( sum('A','N')>=0?"A" : "N");

        return sb.toString();
    }
	private int sum(char l,char r) {
		return surveyMap.get(l) - surveyMap.get(r);
	}
	private void accumulateValue(char key, int value) {
		surveyMap.put(key, surveyMap.get(key)+value);
	}
	private void calculate(char l,char r, int i) {
		if(choices[i]<4) {
			accumulateValue(l, scoreArr[choices[i]-1]);
		}else {
			accumulateValue(r, scoreArr[choices[i]-1]);
		}
	}
}

 

 

'자료구조&알고리즘 > Level1' 카테고리의 다른 글

성격 유형 검사하기  (0) 2022.09.26
신고 결과 받기  (0) 2022.09.24
올바른 괄호  (1) 2022.09.23
크레인 인형뽑기 게임  (1) 2022.09.21
신규 아이디 추천  (0) 2022.09.18

+ Recent posts