[프로그래머스 / C++] 모의고사

Seulguo·2022년 7월 12일
0

Algorithm

목록 보기
47/185
post-thumbnail

🐣 문제

링크 : 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;
   
    int one[5] = {1,2,3,4,5}; 
    int two[8] = {2,1,2,3,2,4,2,5};
    int three[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++){
        if(one[i%5] == answers[i]) cnt1++;
        if(two[i%8] == answers[i]) cnt2++;
        if(three[i%10] == answers[i]) cnt3++;
    }
    
    int maxScore = 0; 
    maxScore = max(max(cnt1,cnt2),cnt3);
    
    if(cnt1 == maxScore) answer.push_back(1);
    if(cnt2 == maxScore) answer.push_back(2);
    if(cnt3 == maxScore) answer.push_back(3);
    
    return answer;
}

0개의 댓글