-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCppTips
More file actions
33 lines (25 loc) · 688 Bytes
/
CppTips
File metadata and controls
33 lines (25 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Resources
https://codeforces.com/blog/entry/10124
https://codeforces.com/blog/entry/15643
https://codeforces.com/blog/entry/16262
https://codeforces.com/blog/entry/16262
### C++ 11
- use range based for loops. can be used for stl containers
```
vector< int > numbers = {2, 3, 5, 7};
for (auto& x : numbers)
x *= 2;
for (auto x : numbers)
cout << x << endl;
```
- lambda functions
```auto heights = vector< int >{ ...some values here... };
auto order = vector< int >(heights.size());
for (int i: range(heights.size()))
order[i] = i;
sort(order.begin(), order.end(),
[&] (const int& a, const& int b) -> bool {
return heights[a] < heights[b];
}
);
```