문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42840
맞힌 코드
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> answers) {
vector<int> answer;
vector<int> v1 = {1,2,3,4,5};
vector<int> v2 = {2,1,2,3,2,4,2,5};
vector<int> v3 = {3,3,1,1,2,2,4,4,5,5};
int one=0, two=0, three=0;
for (int i=0; i<answers.size(); i++){
if (answers[i] == v1[i%5])
one++;
if (answers[i] == v2[i%8])
two++;
if (answers[i] == v3[i%10])
three++;
}
int arr[3] = {one, two, three};
int max = 0;
for (int i=0; i<3; i++){
if (arr[i]>max)
max = arr[i];
}
for (int i=0; i<3; i++){
if (arr[i]==max)
answer.push_back(i+1);
}
return answer;
}
'Algorithm' 카테고리의 다른 글
[프로그래머스] 42842번 카펫 C++ (0) | 2024.11.13 |
---|---|
[프로그래머스] 42839번 소수 찾기 C++ (0) | 2024.11.13 |
[프로그래머스] 86491번 최소직사각형 C++ (0) | 2024.11.13 |
[프로그래머스] 42747번 H-Index C++ (0) | 2024.11.13 |
[프로그래머스] 42748번 K번째수 C++ (0) | 2024.11.12 |