본문 바로가기

Algorithm/Programmers

[Programmers] 로또의 최고 순위와 최저 순위 (C++)

728x90
반응형

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> lottos, vector<int> win_nums) {
    vector<int> answer;
    int cnt1 = 0, cnt2 = 0;
    for(int i = 0; i < 6; i++){
        if(find(win_nums.begin(), win_nums.end(), lottos[i]) != win_nums.end()){
            cnt1++;
            cnt2++;
        }
        else if(lottos[i] == 0){
            cnt1++;
        }
    }
    
    if(cnt1 == 6) answer.push_back(1);
    else if(cnt1 == 5) answer.push_back(2);
    else if(cnt1 == 4) answer.push_back(3);
    else if(cnt1 == 3) answer.push_back(4);
    else if(cnt1 == 2) answer.push_back(5);
    else answer.push_back(6);
    
    if(cnt2 == 6) answer.push_back(1);
    else if(cnt2 == 5) answer.push_back(2);
    else if(cnt2 == 4) answer.push_back(3);
    else if(cnt2 == 3) answer.push_back(4);
    else if(cnt2 == 2) answer.push_back(5);
    else answer.push_back(6);
    
    return answer;
}
728x90
반응형