본문 바로가기
[프로그래머스 C++]/LEVEL 1

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

by AKI(JUNI) 2025. 3. 31.

◈ 문제 설명


◈ 문제 설명 링크

코딩테스트 연습 - 모의고사 | 프로그래머스 스쿨

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 


◈ 작성 코드

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> answers) 
{
    vector<int> answer;
    vector<int> one = {1,2,3,4,5};              // 5
    vector<int> two = {2,1,2,3,2,4,2,5};        // 8
    vector<int> three = {3,3,1,1,2,2,4,4,5,5};  // 10
    vector<int> check = {0,0,0};

    int t = 0;
    int a = 0;
    int b = 0;
    int c = 0;

    while(t < answers.size())
    {
        if(answers[t] == one[a])
        {
            check[0]++;
        }
        if(answers[t] == two[b])
        {
            check[1]++;
        }
        if(answers[t] == three[c])
        {
            check[2]++;
        }
        
        a++;
        b++;
        c++;
        if(a > 4)
        {
            a = 0;
        }
        if(b > 7)
        {
            b = 0;
        }
        if(c > 9)
        {
            c = 0;
        }
        
        t++;
    }
    
    if(check[0] >= check[1] && check[0] >= check[2])
    {
        answer.push_back(1);
        if(check[0] == check[1] && check[0] != check[2])
        {
            answer.push_back(2);
        }
        else if(check[0] != check[1] && check[0] == check[2])
        {
            answer.push_back(3);
        }
        else if(check[0] == check[1] && check[0] == check[2])
        {
            answer.push_back(2);
            answer.push_back(3);
        }
    }
    else if(check[1] >= check[0] && check[1] >= check[2])
    {
        answer.push_back(2);
        if(check[1] != check[0] && check[1] == check[2])
        {
            answer.push_back(3);
        }
    }
    else if(check[2] > check[0] && check[2] > check[1])
    {
        answer.push_back(3);
    }
    
    
    return answer;
}