728x90
https://school.programmers.co.kr/learn/courses/30/lessons/118666
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
1. Java
import java.util.*;
class Solution {
public String solution(String[] survey, int[] choices) {
String answer = "";
char[][] type_info = { {'R','T'},{'C','F'},{'J','M'},{'A','N'} };
int[][] choices_info = { {0,0},{0,3},{0,2},{0,1},{0,0},{1,1},{1,2},{1,3} };
Map<Character,Integer> my_type = new HashMap<>();
for ( int i = 0; i < survey.length; ++i ) {
char type = survey[i].charAt(choices_info[choices[i]][0]);
int choice = choices_info[choices[i]][1];
my_type.put(type, my_type.getOrDefault(type, 0) + choice);
}
for ( char[] tt : type_info ) {
char type = 'Z';
int choice = -1;
for ( char t : tt ) {
int choice_tot = my_type.getOrDefault(t,0);
if ( choice < choice_tot ) {
type = t;
choice = choice_tot;
}
}
answer += type;
}
return answer;
}
}
(오늘 알아낸 사실... 글에 중괄호({) 연속으로 붙어있으면 글 내용 안 보임..)
2. Python
def solution(survey, choices):
answer = ''
type_info = [['R','T'],['C','F'],['J','M'],['A','N']]
choices_info = [[0,0],[0,3],[0,2],[0,1],[0,0],[1,1],[1,2],[1,3]]
my_type = {}
for i in range(len(survey)) :
type = survey[i][choices_info[choices[i]][0]]
choice = choices_info[choices[i]][1]
my_type[type] = my_type.get(type,0) + choice
for tt in type_info :
type = ''
choice = -1
for t in tt :
choice_tot = my_type.get(t,0)
if choice < choice_tot :
type = t
choice = choice_tot
answer += type
return answer
반응형
'코딩 문제 풀기 ( Algorithm problem solving ) > 프로그래머스 ( Programmers )' 카테고리의 다른 글
[프로그래머스(Programmers)][Java,Python] (Lv1) 개인정보 수집 유효기간 (2023 KAKAO BLIND RECRUITMENT) (0) | 2025.03.24 |
---|---|
[프로그래머스(Programmers)][Java,Python] (Lv1) 바탕화면 정리 (0) | 2025.03.21 |
[프로그래머스(Programmers)][Java,Python] (Lv1) 데이터 분석 (PCCE 기출문제 10번) (0) | 2025.03.21 |
[프로그래머스(Programmers)][Java,Python] (Lv1) 햄버거 만들기 (0) | 2025.03.20 |
[프로그래머스(Programmers)][Java,Python] (Lv1) 명예의 전당 (1) (0) | 2025.03.19 |