본문 바로가기

Study/Programmers

(19)
프로그래머스 - 타겟 넘버 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include #include #include using namespace std; int solution(vector numbers, int target) { int answer = 0; vector oper(numbers.size(), false); int len = numbers.size(); sort(numbers.begin(), numbers.end()); for(int i=0; i (-) do{ int num = 0; for(int i=0; i= numbers.size()){ if(sum == target) total++; return; } DFS(number..
프로그래머스 - 소수 찾기 소수를 찾는 것은 쉬우나, 문자열을 입력받아 해당 문자들로 만들 수 있는 모든 수의 조합을 찾는 것을 재귀로 짜보려했으나 잘 되지 않았다. 그래서 next_permutation을 사용했다. 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #include #include #include #include using namespace std; map m; int answer; int find(int num) { if (num
프로그래머스 - 가장 큰 수 쉽다고 생각하였으나 정렬을 쉽게하는 방법을 떠올리지 못해서 시간이 오래 걸렸던 문제이다. 두 문자열을 붙였을 때 그 순서에 따라 더 큰 숫자가 되게끔 정렬을 해줘야 하는데, 이를 각 숫자로 판단하기에는 어렵다. 따라서 정렬 기준 내에서 두 문자열을 미리 붙여보고 더 큰 문자열이 앞에 오도록 정렬하였더니 쉽게 해결이 되었다. 다만, 문제는 "가장 큰 수"를 의미하기 때문에 [0, 0, 0, 0]이 들어올 경우 0을 출력해야한다는 점을 주의해야 한다. 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 #include #include #include usin..