프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제풀이
1. HashMap < K , V > 를 이용하여 key 값에 성격 유형 , Value 값에 점수를 입력
2. 아래 점수 표는 다음 코드와 같이 계산하여 HashMap에 입력
for (int i = 0; i < survey.length; i++) {
String a = String.valueOf(survey[i].charAt(choices[i] / 4));
if (choices[i] != 4) {
hm.put(a, hm.get(a) + Math.abs(4 - choices[i]));
}
}
| choices | 뜻 |
| 1 | 매우 비동의 |
| 2 | 비동의 |
| 3 | 약간 비동의 |
| 4 | 모르겠음 |
| 5 | 약간 동의 |
| 6 | 동의 |
| 7 | 매우 동의 |
나의풀이 ( 코드 )
import java.util.*;
class Solution {
public String solution(String[] survey, int[] choices) {
String answer = "";
HashMap<String, Integer> hm = new HashMap<>();
String[] strArr = {"R", "T", "C", "F", "J", "M", "A", "N"};
for (int i = 0; i < strArr.length; i++) {
hm.put(strArr[i], 0);
}
for (int i = 0; i < survey.length; i++) {
String a = String.valueOf(survey[i].charAt(choices[i] / 4));
if (choices[i] != 4) {
hm.put(a, hm.get(a) + Math.abs(4 - choices[i]));
}
}
for (int i = 0; i < strArr.length; i += 2) {
int a = hm.get(strArr[i]);
int b = hm.get(strArr[i + 1]);
if (a >= b) {
answer += strArr[i];
} else if (b > a) {
answer += strArr[i + 1];
}
}
return answer;
}
}'알고리즘 > 프로그래머스' 카테고리의 다른 글
| [프로그래머스/JAVA 자바] 달리기 경주 (0) | 2024.04.23 |
|---|---|
| [프로그래머스/JAVA 자바] 신고 결과 받기 (0) | 2024.04.21 |
| [프로그래머스/JAVA 자바] 크레인 인형뽑기 게임 (0) | 2024.04.18 |
| [프로그래머스/JAVA 자바] 체육복 (2) | 2024.04.17 |
| [프로그래머스/JAVA 자바] 완주하지 못한 선수 (0) | 2024.04.17 |