int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
std::cin.ignore();
while (T--) {
std::string line, cmd;
std::cin >> cmd;
...
이런 식으로 std::ios::sync_with_studio(false)와 std::cin.tie(nullptr)를 사용하면 잘 나온다.
std::ios::sync_with_studio(false)scanf/printf와 섞어 쓰면 위험.std::cin.tie(nullptr)cin은 cout과 묶여 있다. cin을 호출하기 전에 자동으로 cout.flush()(버퍼 비우기)를 해준다. 하지만 자동 flush는 불필요하게 자주 일어나서 속도를 떨어뜨린다.cin과 cout의 tie를 끊어준다.