Useful functions
This article summarizes the useful but non-farmillar functions in codeing.
Reverse
template <class BidirectionalIterator>
void reverse (BidirectionalIterator first, BidirectionalIterator last);
Reverses the order of the elements in the range [first,last). 比如翻转一个string特别方便。
isdidit, isalpha, isalnum, isspace
判断string是否为数字,字母,whitespace等
substr
Returns a newly constructed string object with its value initialized to a copy of a substring of this object.
The substring is the portion of the object that starts at character position pos and spans len characters (or until the end of the string, whichever comes first).
判断奇偶
x&1 == 0
相当于x%2==0
延伸一下就是判断x的第i位是1还是0, (x>>i) &1, 若为1就是1,若为0就是0 (x>>i) |0, 若为1就是1, 若为0就是0;
vector 去重
unique + resize
sort(result.begin(), result.end());
vector<vector<int> >::iterator it = unique(result.begin(), result.end());
result.resize(it-result.begin());