Make Unreal REAL.
article thumbnail
Level 0. 두 수의 합

Level 0. 두 수의 합 숫자를 앞에 붙이면서 불필요한 밀기 연산이나 메모리 재할당을 최소화하기 위해, 뒤로 붙인 후 마지막에 역순으로 재배열해줬다. #include #include using namespace std; string solution(string a, string b) { string answer = ""; size_t lenA = a.length(), lenB = b.length(); int last = max(lenA, lenB), carry = 0; for (int i = 1; i

article thumbnail
Level 0. 배열 만들기 4

Level 0. 배열 만들기 4 #include #include using namespace std; vector solution(vector arr) { vector stk; for (int i = 0; i < arr.size(); ++i) if (stk.empty() || stk.back() < arr[i]) stk.emplace_back(arr[i]); else stk.pop_back(), --i; return stk; }

article thumbnail
Level 0. 배열 만들기 2

Level 0. 배열 만들기 2 전에 같이 알고리즘 스터디를 하던 형이 재귀로 조합을 만들어 냈던 게 생각나서 비슷한 방법을 써봤다. 현재 수에 0과 5를 하나씩 붙여나가는 방법이다. #include #include #include using namespace std; void rSolution(int l, int r, vector& vec, int val) { if (l

article thumbnail
합집합, 교집합, 차집합

STL 함수를 쓰지 않고 직접 구현하면 다음과 같다. #include #include #include #include #include using namespace std; void print(vector& v); int main(int argc, char* argv[]) { vector setA = {"AA", "AA", "AA", "CC", "DD"}; vector setB = {"AA", "CC", "CC", "EE"}; unordered_map umapA, umapB; set elem; for (string& s : setA) ++umapA[s], elem.emplace(s); for (string& s : setB) ++umapB[s], elem.emplace(s); vector setUnion,..

article thumbnail
Level 2. [1차] 뉴스 클러스터링

Level 2. [1차] 뉴스 클러스터링 문제의 설명 그대로 푼 풀이이다. 모든 영문자를 대문자로 바꾸고, 영문자만 2글자씩 쪼개고, 정렬한 후 set_union(), set_intersection() STL 함수를 이용해 합집합과 교집합의 크기를 구해 해결했다. #include #include #include #include using namespace std; int solution(string str1, string str2) { int answer = 0; vector setA, setB; vector setUnion, setInter; transform(str1.begin(), str1.end(), str1.begin(), ::toupper); transform(str2.begin(), str2..

article thumbnail
Level 0. 커피 심부름

Level 0. 커피 심부름 카페라떼가 아니면 무조건 아메리카노이다. #include #include using namespace std; int solution(vector order) { int answer = 0; for (string& s : order) if (s.find("cafelatte") != string::npos) answer += 5000; else answer += 4500; return answer; }

검색 태그