computer language/C++

백준 2741

달모드 2020. 9. 14. 01:56
#include<iostream>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i=1; i<=n; i++){
        cout << i << "\n";
    }
    return 0;
}

/*
std::cin 은 scanf보다 3배 가까이 느리다.
이유는 cpp의 iostream의 버퍼와 c의 스튜디오 버퍼와 동기화시켜주므로 두개의 버퍼사용효과.
하지만 std::ios_base::sync_with_stdio(false);를 사용하며 동기화를 끊으면
c++만의 독립적인 버퍼를 생성하게 되고 c의 버퍼들과는 병행하여 사용할 수 없게 되며 속도 높아짐.
이때 std::cout << std::endl; 같이 사용하는 경우 20배 이상 속도차이가 난다.

*/

12ms...