풀이 (접근법 암기)
- 반복되는 원소들은
배열 index
에나머지 정리
를 적용!!
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> answers) {
vector<int> answer;
int n1[5] = {1,2,3,4,5};
int n2[8] = {2,1,2,3,2,4,2,5};
int n3[10] = {3,3,1,1,2,2,4,4,5,5};
int cnt1=0,cnt2=0,cnt3=0;
for(int i=0;i<answers.size();i++){
int cur = answers[i];
if(n1[i%5]==cur){
cnt1++;
}
if(n2[i%8]==cur){
cnt2++;
}
if(n3[i%10]==cur){
cnt3++;
}
}
vector<int> v(3);
v.assign({cnt1,cnt2,cnt3});
int max_score = *max_element(v.begin(),v.end());
for(int i=0;i<3;i++){
if(max_score==v[i]){
answer.push_back(i+1);
}
}
return answer;
}