Study Record

[프로그래머스] Level1 - 로또의 최고 순위와 최저 순위 본문

알고리즘

[프로그래머스] Level1 - 로또의 최고 순위와 최저 순위

초코초코초코 2021. 11. 30. 00:42
728x90
#include <string>
#include <vector>

using namespace std;

int getRank(int num){
    if(num >= 6) return 1;
    if(num == 5) return 2;
    if(num == 4) return 3;
    if(num == 3) return 4;
    if(num == 2) return 5;
    return 6;
}

vector<int> solution(vector<int> lottos, vector<int> win_nums) {
    vector<int> answer;
    int winnings_num = 0, max_winnings_num = 0;
    int blank = 0;
    for(int i=0; i<lottos.size(); i++){
        if(lottos[i] == 0){
            blank++;
            continue;
        }
        for(int k=0; k<win_nums.size(); k++){
            if(win_nums[k] == lottos[i]){
                winnings_num++;
                break;
            }
        }
    }
    
    max_winnings_num += winnings_num + blank;
    
    answer.push_back(getRank(max_winnings_num));
    answer.push_back(getRank(winnings_num));
    return answer;
}
728x90