Make Unreal REAL.
article thumbnail
Level 0. 원소들의 곱과 합

Level 0. 원소들의 곱과 합 #include #include #include #include using namespace std; int solution(vector n) { int product = accumulate(n.begin(), n.end(), 1, ::multiplies()); int sum_pow = pow(accumulate(n.begin(), n.end(), 0), 2); return product < sum_pow; }

article thumbnail
Level 2. [3차] 방금그곡

Level 2. [3차] 방금그곡 전형적인 파싱 문제였고 저번과 같이 지문 길이에 비해 풀 만한 문제였다. 다만 테스트 케이스가 참 별로인 문제였는데 istringstream을 통해 공백으로 파싱하면, 입력 중에 빈 문자열이 포함되어 있는 경우 정상적으로 파싱되지 않는다. 근데 문제는 이런 테스트 케이스가 절반을 차지해서, 로직에 문제가 있는 건지 파싱에 문제가 있는 건지 구분할 수 없다는 것이다. 나도 istringstream 파싱 문제 때문에 오전 시간을 다 날려버렸다가, 질문하기에서 겨우 같은 문제를 겪었던 사람을 찾아 해결할 수 있었다. // 이 풀이는 오답 처리된다. #include #include #include #include #include #include #include #include ..

article thumbnail
Level 2. 우박수열 정적분

Level 2. 우박수열 정적분 설명을 잘 따라가면 지문 길이에 비해 어려운 문제는 문제는 아니었다. 이 그래프는 각 구간에서는 1차 함수이므로, 정적분한 넓이가 (b - a) * (f(b) + f(a)) / 2라는 걸 알고 있다면 쉽게 풀 수 있는 문제였다. #include #include #include using namespace std; vector get_collatz(int n) { vector v; while (n != 1) { v.emplace_back(n); if (n & 1) n += n + n + 1; else n >>= 1; } v.emplace_back(1); return v; } vector solution(int k, vector ranges) { vector answer; v..

article thumbnail
Level 2. 괄호 변환

Level 2. 괄호 변환 카카오의 구현 문제는 뭔가 어려울 것 같으면서도, 막상 풀어보면 진짜 못 풀만 한 문제는 안 내는 것 같다. 코드를 작성하고 나서 어딘가에서는 오류가 발생하겠지.. 이게 될까? 하면서 제출했는데 한 번에 성공해서 신기했다. #include #include using namespace std; bool is_balanced(string s) { int numOpen = 0, numClose = 0; for (char c : s) numOpen += (c == '('), numClose += (c == ')'); return (numOpen == numClose); } bool is_right(string s) { stack stck; int nOpen = 0, nClose = 0..

article thumbnail
Level 0. 배열의 원소 삭제하기

Level 0. 배열의 원소 삭제하기 #include #include #include using namespace std; vector solution(vector arr, vector delete_list) { auto pred = [&delete_list](int num) { return find(delete_list.begin(), delete_list.end(), num) != delete_list.end(); }; arr.erase(remove_if(arr.begin(), arr.end(), pred), arr.end()); return arr; }

article thumbnail
Level 0. 주사위 게임 2

Level 0. 주사위 게임 2 #include #include using namespace std; int solution(int a, int b, int c) { unordered_set uset; uset.emplace(a); uset.emplace(b); uset.emplace(c); if (uset.size() == 3) return (a + b + c); else if (uset.size() == 2) return (a + b + c) * (a*a + b*b + c*c); else return (a + b + c) * (a*a + b*b + c*c) * (a*a*a + b*b*b + c*c*c); }

검색 태그