//구글콘솔 광고 추가가
성격 유형 검사하기 문제

 

내 코드
using System;
using System.Text;
using System.Collections.Generic;

public class Solution {
    public string solution(string[] survey, int[] choices) {
        string answer = "";
        StringBuilder answerSB = new StringBuilder();
        Dictionary<char,int> surveyDic = new Dictionary<char,int>()
        {
            { 'R', 0 },
            { 'T', 0 },
            { 'C', 0 },
            { 'F', 0 },
            { 'J', 0 },
            { 'M', 0 },
            { 'A', 0 },
            { 'N', 0 },
        };
     
        char[] c = new char[2];
        for (int i = 0; i < survey.Length; i++)
        {
            c = survey[i].ToCharArray();

            if (choices[i] > 4)
            {
                surveyDic[c[1]] += choices[i] - 4;
            }
            else if (choices[i] < 4)
            {
                surveyDic[c[0]] += 4 - choices[i];
            }
        }
        answerSB.Append(surveyDic['R'] >= surveyDic['T'] ? "R" : "T");
        answerSB.Append(surveyDic['C'] >= surveyDic['F'] ? "C" : "F");
        answerSB.Append(surveyDic['J'] >= surveyDic['M'] ? "J" : "M");
        answerSB.Append(surveyDic['A'] >= surveyDic['N'] ? "A" : "N");
        answer = answerSB.ToString();
        return answer;
    }
}
728x90
반응형

+ Recent posts