λ¬Έμ
μ½λ©ν μ€νΈ μ°μ΅ - λ‘λμ μ΅κ³ μμμ μ΅μ μμ
λ‘λ 6/45(μ΄ν 'λ‘λ'λ‘ νκΈ°)λ 1λΆν° 45κΉμ§μ μ«μ μ€ 6κ°λ₯Ό μ°μ΄μ λ§νλ λνμ μΈ λ³΅κΆμ λλ€. μλλ λ‘λμ μμλ₯Ό μ νλ λ°©μμ λλ€. 1 μμ λΉμ²¨ λ΄μ© 1 6κ° λ²νΈκ° λͺ¨λ μΌμΉ 2 5κ° λ²νΈ
programmers.co.kr
μ½λ
#include <string>
#include <vector>
#include <map>
#include <iostream>
using namespace std;
int check(int n){
if(n<=1) return 6;
return 7-n;
}
vector<int> solution(vector<int> lottos, vector<int> win_nums) {
vector<int> answer;
map<int,int>m;
int best = 0, worst = 0;
for(int lotto: lottos) m[lotto]++;
for(int win: win_nums){
if(m.find(win)!=m.end()) m[win]--;
}
for(auto it=m.begin(); it!=m.end(); it++){
if(it->first==0){
best+=it->second;
worst+=it->second;
}
else if(it->first!=0){
if(it->second==0) best++;
else worst++;
}
}
answer.push_back(check(best));
answer.push_back(check(6-worst));
return answer;
}
νμ΄
μ΅κ³ λ‘ λ§λ κ°μμ μ΅μ λ‘ λ§λ κ°μλ₯Ό ꡬν΄κ°λ μμΌλ‘ ꡬννμ΅λλ€.
- 0μΌ λλ worstμ best μ λΆ ++
- 0μ΄ μλλλ μκ° κ°μ λ best++, μλλΌλ©΄ worst--
- μ΅μ’ μ μΌλ‘ worstλ νλ¦° κ°μμ΄κΈ° λλ¬Έμ λ§λ κ°μλ‘ λ°κΏμ£ΌκΈ° μν΄ 6-worstλ₯Ό ν΅ν΄ μμ κ³μ°
λκΈ