写代码的奇技淫巧整合
可能没啥用。
一、 忘删调试信息也能过题的方法
cerr 会每次刷新缓冲,非常慢,而 clog 并不会这样干。
而且,ios::sync_with_stdio(false); 对 clog 也生效,因此这样子既不用担心 WA,也不用担心 TLE。
在 OJ 做题时,如果担心 RE 时没有输出,可以这样写:
#ifndef ONLINE_JUDGE
clog << unitbuf;
#endif
这样本地会刷新缓冲,OJ 上不会。可以增加一点点容错,但是也没那么实用就是了。
二、std::stack 和 std::queue 用 range for 遍历的方法
std::stack 和 std::queue 基于底层容器 deque 实现,而底层容器被设为 protected,这意味着派生类可以访问其底层容器。下面以 std::stack 为例。
template<class T>
struct mystack:stack<T>{
using stack<T>::c;
};
然后用 mystack<int> stk,就可以 for (int x : stk.c) 来遍历。