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

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

MJ.Lee 2024. 10. 1. 12:41
#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;
}