<문제>
수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다.
1번 수포자가 찍는 방식: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
2번 수포자가 찍는 방식: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ...
3번 수포자가 찍는 방식: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ...
1번 문제부터 마지막 문제까지의 정답이 순서대로 들은 배열 answers가 주어졌을 때, 가장 많은 문제를 맞힌 사람이 누구인지 배열에 담아 return 하도록 solution 함수를 작성해주세요.
<정답>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Solution {
public int[] solution(int[] answers) {
List answer = new List ();
int[] student1 = {1,2,3,4,5};
int[] student2 ={2,1,2,3,2,4,2,5};
int[] student3={3,3,1,1,2,2,4,4,5,5};
int[] score = new int[3];
int max=0;
for(int i=0;i<answers.Length;i++)
{
if(answers[i] == student1[i%5])
score[0] += 1;
if (answers[i] == student2[i%8])
score[1] += 1;
if (answers[i] == student3[i%10])
score[2] += 1;
}
max = score.Max();
for(int i=0;i<3;i++)
{
if (max == score[i])
{
answer.Add(i+1);
}
}
return answer.ToArray();
}
}
'코딩연습 > 프로그래머스 코딩테스트' 카테고리의 다른 글
[프로그래머스]Level1 시저암호 (0) | 2021.02.16 |
---|---|
[프로그래머스]Level1 이상한 문자 만들기 (0) | 2021.02.09 |
[프로그래머스]Level1 평균구하기 (0) | 2021.02.04 |
[프로그래머스]Level1 자릿수더하기 (0) | 2020.10.08 |
[프로그래머스]leve1 서울에서 김서방 찾기 (0) | 2020.07.14 |