Skip to content

Conversation

@Seol-Munhyeok
Copy link
Collaborator

πŸ”— 문제 링크

둜또의 졜고 μˆœμœ„μ™€ μ΅œμ € μˆœμœ„
https://school.programmers.co.kr/learn/courses/30/lessons/77484

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

20λΆ„

✨ μˆ˜λ„ μ½”λ“œ

λ‹€λ“€ PR μ˜¬λ¦¬λŠ”κ±° κΉŒλ¨Ήμ€κ±΄ μ•„λ‹ˆμ£ ...?
κ·Έλ™μ•ˆ μƒˆν•™κΈ°λΌμ„œ λ‹€λ“€ λ°”λΉ μ„œ λͺ»ν•˜μ‹  κ±° 같은데 μ‘°κΈˆμ”©μ΄λΌλ„ PR 계속 λ‚¨κ²¨λ΄…μ‹œλ‹€!
μ΄λ²ˆμ— ν‘Ό λ¬Έμ œλŠ” μ•„μ£Ό μ‰¬μš΄λ¬Έμ œλ‹ˆκΉŒ κ°€λ³κ²Œ λ°”λ‘œ ν’€μ–΄λ³΄μ„Έμš”!

이 문제λ₯Ό ν’€κΈ° μœ„ν•΄μ„œ κ΅¬ν˜„ν•΄μ•Όν•˜λŠ” 것은 λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

  1. 두 배열이 μ£Όμ–΄μ§ˆ λ•Œ, 두 λ°°μ—΄μ—μ„œ μΌμΉ˜ν•˜λŠ” μˆ«μžκ°€ λͺ‡ 개 μžˆλŠ”μ§€λ₯Ό νŒλ‹¨
  2. μΌμΉ˜ν•˜λŠ” κ°œμˆ˜κ°€ μ£Όμ–΄μ§ˆ λ•Œ, 이λ₯Ό λ“±μˆ˜λ‘œ λ°˜ν™˜
  3. lottos λ°°μ—΄μ—μ„œ 0의 개수 μ°ΎκΈ°

μœ„μ˜ μ„Έ κ°€μ§€λ₯Ό μ–΄λ–»κ²Œ κ΅¬ν˜„ν•˜λŠλƒμ— 따라 μ½”λ“œκ°€ 많이 λ‹¬λΌμ§ˆ κ±° κ°™μŠ΅λ‹ˆλ‹€.

μ΅œμ €λ“±μˆ˜λŠ” 0으둜 ν‘œμ‹œλœκ²Œ λ‹€ 꽝일 λ•Œκ°€ μ΅œμ €λ“±μˆ˜μž…λ‹ˆλ‹€. λ”°λΌμ„œ 0은 μ œμ™Έν•˜κ³  λ‚˜λ¨Έμ§€ 숫자둜 λ“±μˆ˜λ₯Ό λ§€κΈ°λ©΄ λ©λ‹ˆλ‹€.
μ΅œκ³ λ“±μˆ˜λŠ” 0으둜 ν‘œμ‹œλœκ²Œ λ‹€ λ§žμ•˜μ„ λ•Œκ°€ μ΅œκ³ λ“±μˆ˜μž…λ‹ˆλ‹€. λ”°λΌμ„œ μ΅œμ €λ“±μˆ˜μΌ λ•Œ λ§žμ€ κ°œμˆ˜μ—μ„œ 0의 개수λ₯Ό λ”ν•˜λ©΄ 그게 μ΅œκ³ λ“±μˆ˜μΌ λ•Œ λ§žμ€ κ°œμˆ˜κ°€ λ©λ‹ˆλ‹€.

def get_rank(my_nums, win_nums):
    my_nums.sort()
    win_nums.sort()
    count = 0
    i = j = 0
    while i < len(my_nums) and j < len(win_nums):
        if my_nums[i] > win_nums[j]:
            j += 1
        elif my_nums[i] < win_nums[j]:
            i += 1
        else:
            count += 1
            i += 1
            j += 1
            
    return count

def solution(lottos, win_nums):
    lottos.sort()
    zero_count = lottos.count(0)
    visible_nums = lottos[zero_count:]
    
    temp = get_rank(visible_nums, win_nums) 
    min_rank = 6 if temp <= 1 else 7 - temp
    temp += zero_count
    max_rank = 6 if temp <= 1 else 7 - temp
    
    return [max_rank, min_rank]

μ €λŠ” λ§žμ€ κ°œμˆ˜κ°€ 1μ΄ν•˜λ©΄ 6등이고, κ·Έ μ™Έμ˜ κ²½μš°μ—λŠ” 7 - λ§žμ€ 개수 둜 λ“±μˆ˜λ₯Ό κ΅¬ν–ˆμŠ΅λ‹ˆλ‹€.
λ‹€λ₯Έ λ°©λ²•μœΌλ‘œλŠ” μ²˜μŒλΆ€ν„° λ§žμ€ κ°œμˆ˜μ™€ λ“±μˆ˜λ₯Ό λ§€ν•‘ν•˜λŠ” Map을 μ‚¬μš©ν•΄μ„œ κ΅¬ν˜„ν•˜λ©΄ 쑰금 더 κΉ”λ”ν•©λ‹ˆλ‹€.

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@mj010504
Copy link
Collaborator

mj010504 commented Oct 9, 2025

#include<bits/stdc++.h>

using namespace std;

vector<int> solution(vector<int> v, vector<int> wv) {
    vector<int> res;
    int unknown = 0;
    int cnt = 0; 

    for(int i = 0; i < v.size(); i++) {
         if(v[i] == 0) {
                unknown++;
                continue;
            }

        for(int j = 0; j < wv.size(); j++) {
           
            if(v[i] == wv[j]) {
                cnt++;
                break;
            }
        }
    }

    int maxx = 7 - unknown - cnt; if(maxx <= 0) maxx = 6; if(maxx >= 7) maxx = 6;
    int minn = 7 - cnt; if(minn >= 7) minn = 6;
    res.push_back(maxx); res.push_back(minn);

    return res;
}

λ‹€μ‹œ μ‘°κΈˆμ”© ν’€μ–΄λ΄…μ‹œλ‹€.. ν•˜ν•˜ πŸ˜…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants