BOJ | 2557번

송치헌·2021년 5월 25일
0
post-thumbnail

Python 풀이

print("Hello World!") #"Hello World!" 출력

C++ 풀이

#include <iostream> //iostream 전처리 (입출력과 관련된 객체들을 정의하는 헤더파일)

int main(){
    std::cout<<"Hello World!";
    return 0; //적어도 되고 안적어도 된다. C++에서는 컴파일러가 알아서 return 0을 해준다.
}

나는 <iostream> 헤더파일을 선언해서 코딩하는 것을 좋아하기 때문에

#include <stdio.h>
>
#include <stdio.h>
>
int main()
{
    printf("Hello World!");
}

이것과 코드가 동일하지만 앞으로 <iostream> 로 헤더를 선언하여 문제를 풀이할 예정...물론 속도는 조금 더 느릴 수 있지만

ios_base::sync_with_stdio(false);
cin.tie(nullptr);

이 코드를 main함수 안에다가 제일 처음에 적어주면 출력버퍼를 비워주기 때문에 더 빠른 속도로 출력이 된다.(정확하게는 모르겠다...좀 더 공부해 봐야지)
참고로 위 코드를 추가한다면 coutprintf, putchar 등을 같이 사용하면 안된다.(버퍼가 분리되었기 때문) cinscanf 같은 것도 같이 사용하면 안됨.

profile
https://oraange.tistory.com/ 여기에도 많이 놀러와 주세요

0개의 댓글