diff --git "a/Lv.1/Lv.1 \353\241\234\353\230\220\354\235\230 \354\265\234\352\263\240 \354\210\234\354\234\204\354\231\200 \354\265\234\354\240\200 \354\210\234\354\234\204.cpp" "b/Lv.1/Lv.1 \353\241\234\353\230\220\354\235\230 \354\265\234\352\263\240 \354\210\234\354\234\204\354\231\200 \354\265\234\354\240\200 \354\210\234\354\234\204.cpp" new file mode 100644 index 0000000..ceff0c9 --- /dev/null +++ "b/Lv.1/Lv.1 \353\241\234\353\230\220\354\235\230 \354\265\234\352\263\240 \354\210\234\354\234\204\354\231\200 \354\265\234\354\240\200 \354\210\234\354\234\204.cpp" @@ -0,0 +1,58 @@ +#include +#include +#include + +using namespace std; + +// 순위를 알려주는 함수 +int get_rank(int corr) { + switch (corr) { + case 0: return 6; + case 1: return 6; + case 2: return 5; + case 3: return 4; + case 4: return 3; + case 5: return 2; + case 6: return 1; + } +} + +vector solution(vector lottos, vector win_nums) { + vector answer; + // 0(알아볼 수 없는 수)의 개수 + int cnt_0 = 0; + // 로또 당첨 번호와 일치하는 개수 + int corr = 0; + + // 오름차순으로 정렬 + sort(lottos.begin(), lottos.end()); + sort(win_nums.begin(), win_nums.end()); + + for (int i = 0, j = 0; i < 6; i++) { + // 알아볼 수 없는 수의 개수 세기 + if (lottos[i] == 0) { + cnt_0++; + continue; + } + + + // 구매한 번호가 작으면 i를 추가하고 + // 당첨번호가 작으면 j를 추가해서 비교해야 함 + // 구매한 번호가 당첨 번호보다 크거나 같을 때 + while (lottos[i] >= win_nums[j]) { + if (lottos[i] == win_nums[j]) { + // 당첨 번호와 일치하면 corr 추가 + corr++; + } + // 다음 당첨번호와 비교 + j++; + } + + } + + // 최고 순위 = 알아볼 수 없는 번호가 전부 당첨번호와 일치할 때 + answer.push_back(get_rank(corr + cnt_0)); + answer.push_back(get_rank(corr)); + + return answer; +} \ No newline at end of file diff --git "a/Lv.2/Lv.2 \355\203\200\352\262\237 \353\204\230\353\262\204.cpp" "b/Lv.2/Lv.2 \355\203\200\352\262\237 \353\204\230\353\262\204.cpp" new file mode 100644 index 0000000..8c26013 --- /dev/null +++ "b/Lv.2/Lv.2 \355\203\200\352\262\237 \353\204\230\353\262\204.cpp" @@ -0,0 +1,29 @@ +#include +#include + +using namespace std; + +int answer = 0; + +void get_target_number(vector numbers, int target, int sum, int index) { + if (index == numbers.size()) { + // 모든 숫자를 다 사용했을 때 종료 + if (sum == target) { + // 만약에 모든 숫자를 다 사용한 결과가 타겟 넘버와 일치하면 answer 추가 + answer++; + } + return; + } + + // 숫자를 다 사용하지 않았을 경우 다음 더했을 때랑 뺄 때의 경우 모두 탐색 + get_target_number(numbers, target, sum + numbers[index], index + 1); + get_target_number(numbers, target, sum - numbers[index], index + 1); + + +} + +int solution(vector numbers, int target) { + get_target_number(numbers, target, 0, 0); + + return answer; +} \ No newline at end of file