Post List

[programmers] 로또의 최고 순위와 최저 순위

 링크: https://programmers.co.kr/learn/courses/30/lessons/77484


로또 정답 번호가 있을 때, 칠칠치 못하게 로또 번호를 잊어버린 주인공의 최저 순위와 최고 순위를 찾는 문제.

잊어버린 번호는 0으로 세팅된다. 이때 0은 와일드카드 느낌으로 이해하면 된다.


코드:


 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
38
39
40
41
42
43
44
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int getOrder(int score)
{
    if (score >= 6)
        return 1;
    else if (score >= 5)
        return 2;
    else if (score >= 4)
        return 3;
    else if (score >= 3)
        return 4;
    else if (score >= 2)
        return 5;
    return 6;
}

vector<int> solution(vector<int> lottos, vector<int> win_nums)
{
    vector<int> answer;
    int findCount = 0;
    int zeroCount = 0;
    for (auto ln : lottos)
    {
        if (ln == 0)
        {
            zeroCount++;
            continue;
        }
        if (find(win_nums.begin(), win_nums.end(), ln) != win_nums.end())
        {
            findCount++;
        }
    }
    int checkCount = zeroCount + findCount;
    int missCount = findCount;
    answer.push_back(getOrder(checkCount));
    answer.push_back(getOrder(missCount));
    return answer;
}

댓글