PAT C++标准库使用

iterator

1
2
3
4
prev(v.end())
next(it)
rbegin(v)
...

algorithm

sort

从大到小排序:

1
sort(a.begin(), a.end(), greater<int>());

vector

删除特定元素

1
v.erase(remove_if(v.begin(), v.end(), pred), v.end());

string

删除特定字符

1
s.erase(remove_if(s.begin(), s.end(), pred), s.end());

find

1
2
size_type pos = s.find(ch);
pos == string::npos ?

queue

priority_queue

1
2
3
4
5
6
struct X;
priority_queue<X, vector<X>, decltype(cmp)> pq(cmp);
priority_queue<X, vector<X>, greater<X>> pq;
pq.push();
pq.top();
pq.pop();

set

合并set

1
s1.insert(s2.begin(), s2.end());

numeric

accumulate

1
2
3
vector<string> vs;
string a;
string res = accumulate(vs.begin(), vs.end(), a);