YunheWang0813
9/18/2019 - 11:31 PM

## C++ Grammer Memo ##

General

  • 万能: #include<bits/stdc++.h>

Vector

  • find:
    • vector没有"count"!
auto p = find(v.begin(), v.end(), "ab");
  • erase:
v.erase(v.begin() + 1);  // vector要用pointer删除
  • insert:
v.insert(v.begin(), "abc");  // for vector<string>
  • swap:
vector<int> f = {1, 2, 3};
swap(f[0], f[2])   // {3, 2, 1}
  • 2D array:
vector<vector<int>> four_ways = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<vector<int>> dp(5, vector<int>(4, 0));

Unordered_set

  • count:
int n = s.count(4);
  • erase:
int n = s.erase("abc");  // can be void as well; return 1 if exist, 0 if not

Unordered_map

Binary Search

  • upper_bound:

  • lower_bound: