Cpp

io優化

cin.tie(0);
ios_base::sync_with_stdio(false);

String

int to string
.to_string()
32位元int to binary string
stoi()``string a2 = bitset<32>(a).to_string();

Vector

vector<int> v(10, 1); // create vector 10 slots value 1 vector<int> v[10]; // create vector 10 blank slots v.erase(v.begin()+i); v.erase(v.begin()+i, v.begin()+j);

Priority Queue

priority_queue<資料型態> pq; priority_queue<int, vector<int>, greater<int>> pq; // 最小優先 priority_queue<int> pq2(pq); // 宣告 pq2 並賦予 pq 的內容 pqpush(val); pq.pop(); // delete but no return bool isEmpty = pq.empty(); // check if is empty pq.size(); // return length
// read each item in pq while( !pq.empty() ){ int val = pq.top(); cout<< val << ' '; pq.pop(); } // use this is a the type of your comparator typedef std::function<bool(int, int)> comp_type; // priority queue using operator < for ordering priority_queue<int, vector<int>, comp_type> first(std::less<int>()); // priority queue using operator > for ordering priority_queue<int, vector<int>, comp_type> second(std::greater<int>());