언어 : C++
통과 : O
내 소스
#include <string>
#include <vector>
#include <iostream>
using namespace std;
vector<int> solution(vector<int> lottos, vector<int> win_nums) {
vector<int> answer;
int zero_cnt = 0;
int match_cnt = 0;
int max_rank = 0;
int min_rank = 0;
for(vector<int>::iterator iter_lo = lottos.begin(); iter_lo != lottos.end(); iter_lo++) {
if (*iter_lo == 0) {
zero_cnt++;
continue;
}
for(vector<int>::iterator iter_win = win_nums.begin(); iter_win != win_nums.end(); iter_win++) {
if(*iter_lo == *iter_win) {
match_cnt++;
}
}
}
max_rank = 7 - (match_cnt + zero_cnt);
min_rank = 7 - match_cnt;
if(max_rank == 7)
max_rank = 6;
if(min_rank == 7)
min_rank = 6;
answer.push_back(max_rank);
answer.push_back(min_rank);
cout << "zero_cnt: " << zero_cnt << ", match_cnt: " << match_cnt << endl;
cout << "max_rank: " << max_rank << ", min_rank: " << min_rank << endl;
return answer;
}
int main() {
vector<int> lottos; // [44, 1, 0, 0, 31, 25]
vector<int> win_nums; // [31, 10, 45, 1, 6, 19] // [3, 5]
lottos.push_back(44);
lottos.push_back(1);
lottos.push_back(0);
lottos.push_back(0);
lottos.push_back(31);
lottos.push_back(25);
win_nums.push_back(31);
win_nums.push_back(10);
win_nums.push_back(45);
win_nums.push_back(1);
win_nums.push_back(6);
win_nums.push_back(19);
solution(lottos, win_nums);
return 0;
}
728x90
반응형
'자료구조 알고리즘 > 코딩테스트' 카테고리의 다른 글
[MySQL] null-safe equal <=>, = (0) | 2022.05.27 |
---|---|
[MySQL] 같지 않다 (0) | 2022.05.27 |
92334 신고 결과 받기 (0) | 2022.02.02 |
Insert into a Cyclic Sorted List (0) | 2022.01.30 |
[다시예정] Flatten a Multilevel Doubly Linked List (0) | 2022.01.30 |