Make Unreal REAL.
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
unique(), remove() 함수 주의사항

vector에 unique(), remove() 함수를 적용해도 실행 전후의 크기는 같다. unique() 함수와 remove() 함수 모두 크기는 동일하지만, 필요 없는 값으로 채워지기 시작하는 반복자 위치를 반환한다. #include #include #include using namespace std; void print(vector& v); int main() { vector v1 = {1, 1, 2, 2, 3, 3, 4, 5, 6}; vector v2(v1); unique(v1.begin(), v1.end()); print(v1); remove(v2.begin(), v2.end(), 2); print(v2); } 출력 1 2 3 4 5 6 4 5 6 ^ 1 1 3 3 4 5 6 5 6 ^

article thumbnail
vector::resize()

지정한 크기만큼 남은 공간을 특정 값으로 채우는 데 사용할 수 있다. #include #include using namespace std; void print(vector& v); void main() { vector v = {1, 2, 3, 4, 5}; v.resize(10, -1); print(v); } 출력 1 2 3 4 5 -1 -1 -1 -1 -1

article thumbnail
unordered_set의 입력 순서 유지

unordered_set의 입력 순서에 따른 원소 순서는 MSVC와 GCC에서 다르다. #include #include using namespace std; void main() { unordered_set uset; uset.emplace(1); uset.emplace(2); uset.emplace(3); uset.emplace(4); uset.emplace(5); uset.emplace(6); for (int n : uset) cout

article thumbnail
비트셋을 벡터로 변환

숫자를 비트셋으로 표현한 후 벡터로 변환 #include #include #include #include using namespace std; template void print(vector result); void main() { // 17을 문자 비트 벡터로 변환 string s = bitset(17).to_string(); vector v1(s.begin(), s.end()); cout

article thumbnail
unordered_map은 역순회가 불가능하다.

How to get the last element of an std::unordered_map? How to get the last element of an std::unordered_map? myMap.rbegin() and --myMap.end() are not possible. stackoverflow.com unordered_map은 역순회가 불가능하므로, 다음과 같이 사용할 수 없다. 특이하게도 MSVC에서는 되는데, GCC에서는 작동하지 않는다. void func() { unordered_map umap {{"A", 1}, {"B", 2}, {"C", 3}}; // 런타임 오류 발생 ! ! auto it = prev(umap.end()); it = umap.end() - 1; } 그러므로 해시..

검색 태그