Bronze Ⅴ
서울의 오늘 날짜를 출력하는 프로그램을 작성하시오.
출력
서울의 오늘 날짜를 "YYYY-MM-DD" 형식으로 출력한다.
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;
}