프로그래머스 레벨 1 모의고사 문제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <string>
#include <vector>
 
using namespace std;
 
vector<int> solution(vector<int> answers) {
    vector<int> answer;
    
    vector<int> p1, p2, p3;
    p1 = {1,2,3,4,5};
    p2 = {2,1,2,3,2,4,2,5};
    p3 = {3,3,1,1,2,2,4,4,5,5};
    
    int iCorrect[3= {0, };
    
    //정답 확인
    for(int i = 0 ; i < answers.size() ; i++)
    {
        if(answers[i] == p1[i % 5])
            iCorrect[0+= 1;
        if(answers[i] == p2[i % 8])
            iCorrect[1+= 1;
        if(answers[i] == p3[i % 10])
            iCorrect[2+= 1;
    }
    
    int maxScore = max(max(iCorrect[0], iCorrect[1]), iCorrect[2]);
    
    //순위 확인
    for(int i = 0 ; i < 3 ; i++)
    {
        if(iCorrect[i] == maxScore)
            answer.emplace_back(i+1);
    }
        
    return answer;
}
 

문제의 포인트를 잘잡자.

 

최고 점수를 낸 1명만 배열에 넣으면되고

동점자가 있는 경우는 123 순서로 나오면된다.

 

'코딩테스트 연습' 카테고리의 다른 글

코딩테스트 - 2016년  (0) 2020.01.07
코딩테스트 - K 번째 수  (0) 2020.01.06
코딩테스트 - 완주하지 못한 선수  (0) 2020.01.03
코딩테스트 - 행렬의 곱셈  (0) 2020.01.03
코딩테스트 - 전파탑 문제  (0) 2020.01.02

+ Recent posts