# 생각

최고 순위는 모르는 숫자가 다 일치한다는 가정으로 볼 수 있어

모르는 숫자의 개수 + 일치한 숫자의 개수가 되고

최저 순위는 모르는 숫자가 다 일치하지 않는다는 가정으로 볼 수 있어

일치한 숫자의 개수만 된다

 

탐색을 통해 0의 개수와 일치하는 숫자의 개수를 찾아 저장해주면 쉽게 해결 가능하다

 

 

# 전체 코드

#include <bits/stdc++.h>
using namespace std;

vector<int> solution(vector<int> lottos, vector<int> win_nums) {
    vector<int> answer;
    int rank[7] = { 6,6,5,4,3,2,1 };
    int correct = 0;
    int unknown = 0;

    for (auto& i : lottos)
    {
        if (i == 0) unknown++;
    }

    for (auto& idx : win_nums)
    {
        auto it = find(lottos.begin(), lottos.end(), idx);
        if (it != lottos.end()) correct++;
    }

    int tpRank = rank[unknown + correct];
    int btRank = rank[correct];

    answer.push_back(tpRank);
    answer.push_back(btRank);

    return answer;
}

 


출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

+ Recent posts