모의고사
URL : https://programmers.co.kr/learn/courses/30/lessons/42840
수포자가 찍는 방식에 대한 연속된 패턴 데이터를 순서대로 처리하면 되는 문제이다.
완전 탐색으로 문제(answers)의 데이터만큼 반복해서 정답인지 확인하고 정답의 가장 높은 사람의 인덱스를 리턴해주면 되는 문제이다.
using System;
using System.Collections.Generic;
using System.Linq;
public class Person{
public int clearCount = 0;
public int [] orderList = null;
public Person(int [] _priority){
orderList = _priority;
}
public void CheckClear(int _index, int _problem){
int orderValue = orderList[(_index % orderList.Length)];
clearCount += ((_problem == orderValue) ? 1 : 0);
}
}
public int[] solution(int[] _problemList) {
List<Person> personList = new List<Person>();
personList.Add(new Person( new int []{1, 2, 3, 4, 5}));
personList.Add(new Person( new int []{2, 1, 2, 3, 2, 4, 2, 5}));
personList.Add(new Person( new int []{3, 3, 1, 1, 2, 2, 4, 4, 5, 5}));
for(int i = 0; i<_problemList.Length;i++){
for(int j = 0; j< personList.Count;j++){
personList[j].CheckClear(i, _problemList[i]);
}
}
List<int> tempList = new List<int>();
int maxCount = personList.Max( obj => obj.clearCount);
for(int i =0; i< personList.Count;i++){
if(personList[i].clearCount == maxCount){
tempList.Add((i+1));
}
}
return tempList.ToArray();
}
★★☆☆☆
반응형
댓글