Coding Test - cpp/Greedy
[프로그래머스 lv 1 ] - 모의고사
에드윈H
2021. 4. 22. 19:23
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> answers) {
vector<int> answer;
int arr1[5] = { 1,2,3,4,5 };
int arr2[8] = { 2,1,2,3,2,4,2,5 };
int arr3[10] = { 3,3,1,1,2,2,4,4,5,5 };
vector<int> result(3, 0);
for (int i = 0; i < answers.size(); i++)
{
if (arr1[i % 5] == answers[i])
{
result[0] += 1;
}
if (arr2[i % 8] == answers[i])
{
result[1] += 1;
}
if (arr3[i % 10] == answers[i])
{
result[2] += 1;
}
}
int max = result[0] > result[1] ? result[0] : result[1];
max = max > result[2] ? max : result[2];
for (int i = 0; i < 3; i++)
{
if (result[i] == max)
{
answer.push_back(i + 1);
}
}
return answer;
}