본문 바로가기

코딩테스트/프로그래머스

[Level 1][C++] 모의고사

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> answers) {
    
    vector<vector<int>> students(3);
    students[0] = {1,2,3,4,5};
    students[1] = {2,1,2,3,2,4,2,5};
    students[2] = {3,3,1,1,2,2,4,4,5,5};
    
    vector<int> counts = {0, 0, 0};
    
    for(int j=0; j<students.size(); j++) 
    {
        int testCount =0;
        for(int i=0; i<answers.size(); i++)
        {
            if(students[j][testCount] == answers[i])
                counts[j]++;
            testCount++;
            if(testCount ==students[j].size())
                testCount =0;
        }
    }
     
    vector<int> copyCounts = counts;
    sort(counts.begin(), counts.end(), greater<int>());    
    vector<int> answer;
    for(int i=0; i<counts.size(); i++)
        if(copyCounts[i]==counts[0])
            answer.push_back(i+1);
    return answer;
}

'코딩테스트 > 프로그래머스' 카테고리의 다른 글

[Level 1][C++] N으로 표현  (0) 2024.10.01
[Level 1][C++] 체육복  (0) 2024.10.01
[Level 1][C++] 완주하지 못한 선수  (0) 2024.10.01
[Level 1][C++] 2016년  (0) 2024.10.01
[Level 1][C++] K번째 수  (0) 2024.10.01