容器類
string
static constexpr size_type npos = size_type(-1); // npos = -1
// 從 pos 開始查找某個子串,找不到返回 npos (即-1),否則返回第一次出現(xiàn)的下標(biāo)
constexpr size_type find(const basic_string& str, size_type pos = 0) const noexcept;
// 返回子串 [pos, pos + count - 1] 若 count 省略,則返回 [pos, s.size() - 1] 的子串
constexpr basic_string substr( size_type pos = 0, size_type count = npos ) &&;
vector
vector<T> a, b;
...
a = b; // 將 a 中內(nèi)容復(fù)制到 b
set, multiset
multiset<int> ms;
int x = *(--ms.end()); // 查詢集合中的最大值
算法 <algorithm>
隨機(jī)化
mt19937 rnd(time(NULL)); // 用當(dāng)前Epoch到現(xiàn)在的秒數(shù)定義一個隨機(jī)種子
unsigned int a = rnd(); // 返回一個 32 位無符號隨機(jī)整數(shù)
mt19937_64 rndll(time(NULL)); // 定義一個 64 位的隨機(jī)種子
ull a = rndll(); // 返回一個 64 位無符號隨機(jī)整數(shù)
// 將 [first, last) 隨機(jī)打亂,隨機(jī)種子是 g
template< class RandomIt, class URBG >
void shuffle( RandomIt first, RandomIt last, URBG&& g );
// 生成隨機(jī)排列
int a[N+5];
for (int i = 1; i <= n; i++) a[i] = i;
shuffle(a + 1, a + n + 1, rnd);
二分
// 使用自定義比較函數(shù):返回第一個 comp(*it, value) 為 false 的位置,沒找到返回 last
constexpr ForwardIt lower_bound( ForwardIt first, ForwardIt last, const T& value, Compare comp );
其他語法相關(guān)內(nèi)容
引用所占空間與指針相同