쉬운 문제임. 다만 1, 2, 3번이 제출하는 정답을 쓰기 귀찮았다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> answers) {
vector<int> answer;
vector<vector<int>> ans(3);
ans[0] = { 1, 2, 3, 4, 5 };
ans[1] = { 2, 1, 2, 3, 2, 4, 2, 5 };
ans[2] = { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 };
vector<int> cnt(3, 0);
for (int i = 0; i < 3; i++)
{
int ind = 0;
for (int j = 0; j < answers.size(); j++)
{
if (answers[j] == ans[i][ind])
cnt[i]++;
ind = (ind + 1) % ans[i].size();
}
}
int max = *max_element(cnt.begin(), cnt.end());
for (int i = 0; i < 3; i++)
if (cnt[i] == max)
answer.push_back(i + 1);
return answer;
}
'Coding_Test 연습 > Programmers' 카테고리의 다른 글
[프로그래머스] (C++) LV1 폰켓몬 (0) | 2022.04.16 |
---|---|
[프로그래머스] (C++) LV1 체육복 (0) | 2022.04.15 |
[프로그래머스] (C++) LV1 K번째수 (0) | 2022.04.14 |
[프로그래머스] (C++) LV1 완주하지 못한 선수 (0) | 2022.04.14 |
[프로그래머스] (C++) LV1 소수 만들기 (0) | 2022.04.13 |