std::unordered_map map보다 더 빠른 탐색을 위한 자료구조 해쉬테이블로 구현한 자료구조 O(1)의 시간복잡도를 가짐 Map의 경우 O(log n)의 시간복잡도를 가짐 #include 을 선언하면 사용 가능 std::pair으로 구성되며 key가 유사한 데이터가 많으면 성능이 떨어짐 unordered_map 정렬하기 각 Value로 정렬한 후 출력을 진행하는 간단한 로직 #include #include void main() { std::unordered_map _map; _map.insert({"a",1}); _map.insert({"b",4}); _map.insert({"c",3}); _map.insert({"d",2}); //use vector for sorting std::vector..
c++ std::string은 python의 split과 같은 tokenize 함수를 별도 제공하지 않는다. 따라서 여러가지 방법으로 string을 tokenizing할 수 있으며, 두 가지 방법을 소개하려고한다. stringstream std::vector split(std::string input, char delimiter) { std::vector answer; std::stringstream ss(input); std::string temp; while (getline(ss, temp, delimiter)) { answer.push_back(temp); } return answer; }; std::string line("test\test2\test3"); std::vector tokens = s..
c++의 std::string에는 contains함수가 존재하지 않는다. 이를 대신하기 위해 find 함수가 존재한다. [function origin] size_t find (const string& str, size_t pos = 0) const; size_t find (const char* s, size_t pos = 0) const; size_t find (const char* s, size_t pos, size_t n) const; size_t find (char c, size_t pos = 0) const; [parameter] str : 찾고자 하는 문자열 pos : str을 pos위치부터 찾기 시작 s : 캐릭터형의 배열을 가리키는 포인터 n : 연속으로 일치해야 하는 최소 길이 c : 찾고..