CodingTest Practice/Programmers

프로그래머스 : 로또의 최고 순위와 최저 순위 (C++, Lv.1)

몽땅마니아(MDD) 2021. 12. 30. 15:24

 

 

 

 

 

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> solution(vector<int> lottos, vector<int> win_nums) {
    vector<int> answer;
    int x= 0, same = 0;
    
    sort(lottos.begin(), lottos.end());
    sort(win_nums.begin(),win_nums.end());
    
    int l_point = 0, w_point = 0;
    while(l_point < 6 && w_point < 6){
        //0이 있는 경우
        if(lottos[l_point] == 0) {
            x++;
            l_point++;
            continue;
        }
        
        //같은 경우
        if(lottos[l_point] == win_nums[w_point]) {
            same++;
            l_point++; w_point++;
            continue;
        }
        //다른 경우 1 - lottos가 더 큰 경우
        else if(lottos[l_point] > win_nums[w_point]) {
            w_point++;
            continue;
        }
        //다른 경우 2
        else {
            l_point++;
            continue;
        }        
    } //while 종료
    
    //최고 순위 삽입
    int high = same + x;
    if(high <= 1) answer.push_back(6);
    else answer.push_back(7-high);
    
    //최저 순위 삽입
    if(same <= 1) answer.push_back(6);
    else answer.push_back(7-same);
    
    return answer;
}