Some C++ Tricks from Codeforces
Some C++ Tricks from Codeforces
Here, In folder C++.
I choose some of them which is useful for me and note them in these blog.
all(x)
1 | |
before:
1 | |
now:
1 | |
before:
1 | |
now:
1 | |
std::unique
We know that std::unique won’t delete the rest number, but put them in the end.For example, vec = {1, 1, 2, 2, 3, 2, 1} may become {1, 2, 3, 2, 1, 2, 1}. It not good.We can do like this:
1 | |
read()
1 | |
Faster and Shorter.
before:
1 | |
now:
1 | |
我为什么要用阴文。。。写不下去了。。。
std::generate
将给定的区间用给定的函数赋值。举个例子:
1 | |
配合 read 可以快速读入数组。
1 | |
现在变成了
1 | |
使用 generate_n 还可以写成:
1 | |
输出一个数的二进制
使用 std::bitset 可以这样:
1 | |
lambda 表达式
见我的另一篇 blog。
std::max
1 | |
{}
1 | |
- 好像没了
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!