say repository

[프로그래머스] 모의고사 c++ 본문

알고리즘 문제 풀이/프로그래머스

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

부끄러엇피치 2022. 3. 17. 17:11
728x90

https://programmers.co.kr/learn/courses/30/lessons/42840

출처: 프로그래머스

 

코딩테스트 연습 - 모의고사

수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는

programmers.co.kr

 

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

//수포자 3명 규칙
int p1[5] = {1,2,3,4,5};
int p2[8] = {2,1,2,3,2,4,2,5};
int p3[10] = {3,3,1,1,2,2,4,4,5,5};
    
vector<int> solution(vector<int> answers) {
    vector<int> answer;
    vector<int> score = {0,0,0};
    int max_score = 0;
    
    //완전 탐색
    for(int i=0; i<answers.size();i++){
        if (answers[i] == p1[i%5])
            score[0]++;
        if (answers[i] == p2[i%8])
            score[1]++;
        if (answers[i] == p3[i%10])
            score[2]++;
    }
    //max_score = max(max(score[0],score[1]), score[2]);
    max_score = *max_element(score.begin(), score.end());
    for(int i=0; i<score.size();i++){
        if (score[i] == max_score){
            answer.push_back(i+1);
        }
    }
    
    return answer;
}