using System;
public class Solution {
public string solution(string[] survey, int[] choices) {
string answer = "";
int R = 0;
int C = 0;
int J = 0;
int A = 0;
for (int i = 0; i < survey.Length; ++i)
{
if(survey[i] == "RT") R += Add(choices[i], R);
else if(survey[i] == "TR") R -= Add(choices[i], R);
else if (survey[i] == "CF") C += Add(choices[i], C);
else if (survey[i] == "FC") C -= Add(choices[i], C);
else if (survey[i] == "JM") J += Add(choices[i], J);
else if (survey[i] == "MJ") J -= Add(choices[i], J);
else if (survey[i] == "AN") A += Add(choices[i], A);
else if (survey[i] == "NA") A -= Add(choices[i], A);
}
if (R >= 0) answer += "R";
else answer += "T";
if (C >= 0) answer += "C";
else answer += "F";
if (J >= 0) answer += "J";
else answer += "M";
if (A >= 0) answer += "A";
else answer += "N";
return answer;
}
public int Add(int choice, int type)
{
if (choice == 1) type = 3;
else if (choice == 2) type = 2;
else if (choice == 3) type = 1;
else if (choice == 4) type = 0;
else if (choice == 5) type = -1;
else if (choice == 6) type = -2;
else if (choice == 7) type = -3;
return type;
}
}
'C# 알고리즘 코드카타' 카테고리의 다른 글
71. 개인정보 수집 유효기간 (0) | 2024.01.25 |
---|---|
70. 바탕화면 정리 (0) | 2024.01.23 |
68. 햄버거 만들기 (0) | 2024.01.16 |
67. 둘만의 암호 (0) | 2024.01.15 |
66. 대충 만든 자판 (0) | 2024.01.12 |