The main priority queues and strings bb about it. Oh, there is bitset
.
Priority Queue
- It is easy to define:
priority_queue<int> pq;
- The interior is a heap.
Basic Operations
pq.top()
Take the top of the stack elements; (nofront()
way!)pq.push(x)
insert;pq.pop()
Delete (delete the top of the heap);pq.empty()
Judgment is empty.
Custom priority
- The maximum heap:
priority_queue<int> pq;
- Minimum heap:
priority_queue< int, vector<int>, greater<int> > pq;
- There are actually custom-priority
cmp
method (the first priority of the biggest teams):Supplements algorithm [4] - STL usage large column ody>1
2
3
4
5
6
7
8struct
{ BOOL operator () ( const int A, const int B) const { return A> B; }};The priority_queue < int , Vector < int >, CMP> PQ; // this time is the minimum heap
example
- One hundred training 4078: http://bailian.openjudge.cn/practice/4078/
String
The definition easier: string s;
Basic Operations
s.size()
String length (starting with index 0);s.substr(a, n)
Substring configuration, a is the first subscript character, n is an substring character length;s'find(it1, it2, x)
Pointerit1
andit2
find intermediate characterx
; (s.find(x)
entires
lookupx
)s.erase(a)
Removing elements, A looks like a pointer, and can befind
combined with the removal of the specified character, such ass.erase(std::find(s.begin(), s.end(), ' '));
removing any spaces;s.empty()
It determines whether null;- Support
push_back
andpop_back
;
- Support
+
,=
and==
operations.
Traversal operation
- You can
auto it = s.begin(); it != s.end(); it++
traverse; - But I generally use
int i = 0; i < s.size(); i++
to traverse.
And digital conversion
String-to-digital
stoi
,stol
,stoll
: String to Integer;stof
,stod
,stold
: String float switch;
Digital to String
to_string
Direct turn intostd::string
.
Bit vector
definition: bitset<length> b(value);
Basic Operations
- Bit computing support
&
,^
,<<
,>>
and so on; to_string()
Into a string;to_ulong()
,to_ullong()
Is converted to an unsigned integer;flip(i)
The i-th bit inverse, index from 0.flip()
All bitwise.