반응형
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/42840
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
문제 요약
수포자 1,2,3 중 가장 답을 많이 맞힌 사람을 반환하는 함수 만들기
풀이
using System;
using System.Linq;
using System.Collections.Generic;
public class Solution {
public int[] solution(int[] answers) {
int[] results = new int[3];
List<int> answer = new List<int>();
List<int> list1 = new List<int>() { 1, 2, 3, 4, 5 };
List<int> list2 = new List<int>() { 2, 1, 2, 3, 2, 4, 2, 5 };
List<int> list3 = new List<int>() { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 };
while (true)
{
if (list1.Count() < answers.Length) list1.AddRange(list1);
if (list2.Count() < answers.Length) list2.AddRange(list2);
if (list3.Count() < answers.Length) list3.AddRange(list3);
if (list1.Count() >= answers.Length && list2.Count() >= answers.Length && list3.Count() >= answers.Length) break;
}
for (int i = 0; i < answers.Length; i++)
{
if (answers[i] == list1[i]) results[0]++;
if (answers[i] == list2[i]) results[1]++;
if (answers[i] == list3[i]) results[2]++;
}
for (int i = 0; i < results.Length; i++)
{
if (results[i] == results.Max()) answer.Add(i + 1);
}
return answer.ToArray();
}
}
하루 목표를 작게 잡으니까 성취감이 크다!
반응형
'Algorithm > Programmers' 카테고리의 다른 글
[C#]프로그래머스 42747 H-Index - Hide (1) | 2024.12.03 |
---|---|
[C#]프로그래머스 12949 행렬의 곱셈 - Hide (0) | 2024.12.01 |
[C#]프로그래머스 136798 기사단원의 무기 - Hide (0) | 2024.11.29 |
[C#]프로그래머스 42586 기능개발 - Hide (0) | 2024.11.27 |
[C#]프로그래머스 135808 과일 장수 - Hide (0) | 2024.11.24 |