프로그래머스 77484 로또의 최고 순위와 최저 순위

Jmnote (토론 | 기여)님의 2023년 12월 16일 (토) 19:11 판 (새 문서: ==개요== {{프로그래머스|레벨=1|페이지=3|분류=2021 Dev-Matching: 웹 백엔드 개발자(상반기)}} 분류: 약수 ==C++== <syntaxhighlight lang='cpp'> #include <...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

프로그래머스 77484 로또의 최고 순위와 최저 순위

2 C++

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> lottos, vector<int> win_nums) {
    int zeroCount = 0;
    int matchCount = 0;
    for(const int& l: lottos) {
        if(l == 0) {
            zeroCount++;
            continue;
        }
        for(const int& w: win_nums) {
            if(l == w) {
                matchCount++;
                break;
            }
        }
    }
    int high = 7-matchCount-zeroCount;
    int low = 7-matchCount;
    if(high>6) high=6;
    if(low>6) low=6;
    return vector<int>{high, low};
}