# CPP Library ![library_function_thumbnail](https://hackmd.io/_uploads/Syx3odQFi1l.png) :::info [TOC] ::: <br/> ## 常見標準函式庫總覽 | **標頭檔(Header)** | **主要功能** | **常用類別 / 函式** | |----------------|--------------------------|-----------------------------| | `<iostream>` | 標準輸入輸出 | `cin`, `cout`, `cerr`, `endl` | | `<iomanip>` | 控制輸出格式 | `setprecision`, `fixed`, `setw` | | `<cstdio>` | C 風格輸入輸出 | `printf`, `scanf`, `sprintf`, `sscanf` | | `<cstdlib>` | 亂數、轉換、系統函式 | `rand`, `srand`, `atoi`, `atof`, `exit` | | `<cstring>` | C 風格字串處理 | `strlen`, `strcpy`, `strncpy`, `strcmp`, `strcat` | | `<string>` | C++ `std::string` 處理 | `string`, `substr`, `find`, `replace` | | `<cmath>` | 數學運算 | `sqrt`, `pow`, `abs`, `ceil`, `floor`, `log` | | `<algorithm>` | 常見演算法 | `sort`, `binary_search`, `lower_bound`, `reverse` | | `<vector>` | 動態陣列 | `vector`, `push_back`, `pop_back`, `size`, `clear` | | `<stack>` | 堆疊(LIFO) | `stack`, `push`, `pop`, `top`, `empty` | | `<queue>` | 佇列(FIFO) | `queue`, `push`, `pop`, `front`, `empty` | | `<map>` | 關聯式映射 | `map`, `insert`, `erase`, `find`, `count` | | `<unordered_map>` | 哈希映射 | `unordered_map`, `insert`, `erase`, `find` | | `<set>` | 集合(無重複排序) | `set`, `insert`, `erase`, `count`, `find` | | `<bitset>` | 位元操作 | `bitset`, `set`, `reset`, `flip`, `count` | | `<random>` | 亂數產生 | `mt19937`, `uniform_int_distribution`, `shuffle` | | `<chrono>` | 計時 | `chrono::high_resolution_clock`, `duration_cast`, `milliseconds` | | `<fstream>` | 檔案讀寫 | `ifstream`, `ofstream`, `fstream`, `open`, `close` | <br/> ## 常用資料結構函式庫 | **資料結構** | **標頭檔(Header)** | **主要函式 / 類別** | |-----------|------------|----------------------------| | 陣列(靜態) | `<array>` | `array` | | 向量(動態) | `<vector>` | `vector` | | 鏈結串列 | `<list>` | `list` | | 堆疊 | `<stack>` | `stack` | | 佇列 | `<queue>` | `queue`, `priority_queue` | | 集合(排序) | `<set>` | `set` | | 集合(無序) | `<unordered_set>` | `unordered_set` | | 哈希映射 (Hash) | `<unordered_map>` | `unordered_map` | | 關聯式映射 | `<map>` | `map` | <br/> ## 常用演算法函式庫 | **演算法類別** | **標頭檔(Header)** | **主要函式 / 類別** | |-----------|------------|----------------------------| | 排序 | `<algorithm>` | `sort`, `partial_sort`, `nth_element` | | 搜尋 | `<algorithm>` | `binary_search`, `lower_bound`, `upper_bound` | | 貪婪演算法 | `<algorithm>` | `max_element`, `min_element` | | 動態規劃 | `<vector>` | `vector`, `fill`, `memset` | | 數學 | `<numeric>` | `accumulate`, `gcd`, `lcm` | | 字串處理 | `<string>` | `substr`, `find`, `replace`, `stoi` | | 位元運算 | `<bitset>` | `bitset`, `set`, `reset`, `flip` | <br/> ## 常見競程與效能優化用途 | **用途** | **標頭檔(Header)** | **主要函式 / 類別** | |-----------|------------|----------------------------| | 快速輸入輸出 | `<iostream>` / `<cstdio>` | `ios::sync_with_stdio(false)`, `cin.tie(0)`, `scanf`, `printf` | | 亂數 | `<random>` | `mt19937`, `uniform_int_distribution` | | 計時 | `<chrono>` | `chrono::high_resolution_clock` | | 記憶體管理 | `<cstring>` | `memset`, `memcpy` | <br/> ## APCS 大致必須的標頭檔 | **用途** | **標頭檔(Header)** | **主要函式 / 類別** | |-----------|------------|----------------------------| | 快速輸入輸出 | `<iostream>` / `<cstdio>` | `ios::sync_with_stdio(false)`, `cin.tie(0)`, `scanf`, `printf` | | 記憶體管理 | `<cstring>` | `memset`, `memcpy` | | 亂數 | `<random>` | `mt19937`, `uniform_int_distribution` | | 計時(⍻) | `<chrono>` | `chrono::high_resolution_clock` | <br/> :::spoiler Relevant - [大學程式先修檢測](https://apcs.csie.ntnu.edu.tw/) - [ZeroJudge 平台](https://zerojudge.tw/) - [LeetCOde 平台](https://leetcode.com/) :::