[10699] 오늘 날짜

sky·2022년 8월 4일
0

BaekJoon Online Judge(B)

목록 보기
37/98
post-thumbnail

문제

Bronze Ⅴ

서울의 오늘 날짜를 출력하는 프로그램을 작성하시오.

출력
서울의 오늘 날짜를 "YYYY-MM-DD" 형식으로 출력한다.


Solution

C++

#include <iostream>
#include <ctime>
#include <string>
#include <stdio.h>

const std::string currentDateTime() {
    time_t     now = time(0);
    struct tm  tstruct;
    char       buf[80];
    tstruct = *localtime(&now);
    strftime(buf, sizeof(buf), "%Y-%m-%d",&tstruct);
    return buf;
}

int main() {
    std::cout << currentDateTime();
}

현재 날짜와 시간을 출력하기 위해선 위 코드처럼 작성한다. 하지만 백준에서는 아래처럼 간단하게 작성만 해도 정답처리가 된다. 단순히 문자열을 출력하라는 문제였다.

#include <iostream>

int main(){
    std::cout << "2022-08-04";
    return 0;
}

Total Time

  • 2022-08-04 | 14:46 - 14:55 Success!
profile
개발자가 되고 싶은 1人

0개의 댓글

관련 채용 정보