주녘공부일지

[프로그래머스 C#] Lv.1 성격 유형 검사하기 본문

Programmers - C#/CodingTest Lv.1

[프로그래머스 C#] Lv.1 성격 유형 검사하기

주녘 2023. 8. 22. 18:29
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/118666

1. 정답코드 및 핵심 아이디어, 유의사항

- 문제를 읽자마자 Dictionary를 떠올려야 함

- 어피치형과 네오형 점수를 뽑는 수식을 만들면 편하게 사용할 수 있음

    using System;
    using System.Collections.Generic;
    using System.Text;

    public class Solution
    {
        public string solution(string[] survey, int[] choices)
        {
            string answer = "";

            Dictionary<char, int> dict = new Dictionary<char, int>
            {
                {'R', 0}, {'C', 0}, {'J', 0}, {'A', 0},
                {'T', 0}, {'F', 0}, {'M', 0}, {'N', 0},
            };

            for (int i = 0; i < survey.Length; i++)
            {
                if (choices[i] < 4)
                    dict[survey[i][0]] += (choices[i] * 3) % 4;
                else if (choices[i] > 4) // 뒤에 꺼
                    dict[survey[i][1]] += choices[i] - 4;
            }

            answer += (dict['R'] >= dict['T']) ? "R" : "T";
            answer += (dict['C'] >= dict['F']) ? "C" : "F";
            answer += (dict['J'] >= dict['M']) ? "J" : "M";
            answer += (dict['A'] >= dict['N']) ? "A" : "N";

            return answer;
        }
    }
728x90