: → Killercat: cin/cout有一套加速的trick
: → Killercat: https://tinyurl.com/y55xhery 可以參考這篇 刷榜能用
說到洗榜我興趣就來了 XDDDD
這篇的意思是說 cout 只要把 sync_with_stdio 關掉就可以變快
std::ios_base::sync_with_stdio(false);
然而這和哪套 function 哪個語言無關,它是底層 Standard I/O 的 buffer 行為,
所以 C 的 printf 家族也有一樣的招式:
setvbuf(stdout, NULL, _IOFBF, 0);
_IOFBF 的意思是 fully buffered I/O
而預設值是對 terminal 或 pipe 是 line buffered,
對 file 是 block (full) buffered,
對 stderr 則是 unbuffered (就算沒有換行也立即印出來),
大家可以參考 setvbuf 的 man page 就有清楚說明了
結論:現在 printf 和 cout 平手了