• Home
  • About
    • Jiwon Jeong photo

      Jiwon Jeong

      끊임없이 배우며 성장하는 엔지니어

    • Learn More
    • Email
    • Github
  • Posts
    • All Posts
    • All Tags
    • All Categories
  • Projects

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

16 May 2021

Reading time ~1 minute

풀이 (성공)

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

using namespace std;

bool compare(int a, int b){
    if(a>b){
        return true;
    }else{
        return false;
    }
}

vector<int> solution(vector<int> lottos, vector<int> win_nums) {
    vector<int> answer;
    int low=0;
    vector<int> prev;
    int high=0;
    
    sort(lottos.begin(), lottos.end(), compare);
    sort(win_nums.begin(), win_nums.end(), compare);
    
    
    int i=0;
    while(lottos[i]!=0 && i<6){
        for(int j=0; j<6; j++){
            if(lottos[i]==win_nums[j]){
                low++;
            }
        }
        i++;
    }
    high = low;
    
    if(i!=6){
        for(int j=i; j<6; j++){
            high++;
        }
    }
    
    if(high==6){
        answer.push_back(1);
    }else if(high==5){
        answer.push_back(2);
    }else if(high==4){
        answer.push_back(3);
    }else if(high==3){
        answer.push_back(4);
    }else if(high==2){
        answer.push_back(5);
    }else{
        answer.push_back(6);
    }
    
    if(low==6){
        answer.push_back(1);
    }else if(low==5){
        answer.push_back(2);
    }else if(low==4){
        answer.push_back(3);
    }else if(low==3){
        answer.push_back(4);
    }else if(low==2){
        answer.push_back(5);
    }else{
        answer.push_back(6);
    }


    return answer;
}


PS Share Tweet +1