문제링크
https://school.programmers.co.kr/learn/courses/30/lessons/118666
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
문제 핵심
너무길다
알고리즘
1.검사 알파벳으로분리
2.각 알파벳 점수 부여
3.문제 조건대로 비교해서 붙히기
코드
public static String solution(String[] survey, int[] choices) {
String answer = "";
Map<String, Integer> map = new HashMap<>();
for (String s : survey) {
map.putIfAbsent(s.charAt(0) + "", 0);
map.putIfAbsent(s.charAt(1) + "", 0);
}
System.out.println(map);
for (int i = 0; i < choices.length; i++) {
int score = 0;
int choice = choices[i];
String sur = "";
if (choice <= 3) {
sur = survey[i].split("")[0];
} else if (choice == 4) {
System.out.println("4임");
continue;
} else {
sur = survey[i].split("")[1];
}
switch (choice) {
case 1:
case 7:
score = 3;
break;
case 2:
case 6:
score = 2;
break;
case 3:
case 5:
score = 1;
break;
case 4:
score = 0;
break;
}
System.out.println("sur: " + sur + " socre: " + score);
map.put(sur, map.get(sur) + score);
}
System.out.println(map);
Map<String, String> types = new LinkedHashMap<>();
types.put("R", "T");
types.put("C", "F");
types.put("J", "M");
types.put("A", "N");
for (Map.Entry<String, String> entry : types.entrySet()) {
String f = entry.getKey();
String s = entry.getValue();
int fc = map.containsKey(f) ? map.get(f) : 0;
int sc = map.containsKey(s) ? map.get(s) : 0;
System.out.println("f: " + f + " / fc: " + fc
+ " / s: " + s + " / sc: " + sc);
if (fc > sc) {
answer += f;
} else if (sc > fc) {
answer += s;
} else {
answer += f.compareTo(s) < 0 ? f : s;
}
}
System.out.println(answer);
return answer;
}
결과

gpt피드백
① 알고리즘 평가
평가
현재 흐름은 정확해.
개선점 1 — 처음 Map 초기화가 필요 없음
개선점 2 — 점수 계산을 switch 없이 계산 가능
② 코드 평가
개선점 1 — split("")은 과함
개선점 2 — String보다 char가 자연스러움
개선점 3 — LinkedHashMap까지 필요하지 않음
후기
문제가 너무 길어서 귀찮은 문제였다
'코테 > lvl1' 카테고리의 다른 글
| 프로그래머스 신규 아이디 추천(lvl1) 풀어보기 (0) | 2026.10.06 |
|---|---|
| 프로그래머스 1차다트 게임(lvl1) 풀어보기 (0) | 2026.10.05 |
| 프로그래머스 예산(lvl1) 풀어보기 (0) | 2026.10.05 |
| 프로그래머스 연습문제(lvl1) 풀어보기 (0) | 2026.09.08 |
| 프로그래머스 명예의 전당(1)(lvl1) 풀어보기 (0) | 2026.09.08 |