문제 |
10699번: 오늘 날짜
서울의 오늘 날짜를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
코드 |
#include <iostream>
#include <ctime>
using namespace std;
int main() {
time_t t = time(nullptr);
tm *now = localtime(&t);
cout << (now->tm_year + 1900) << '-';
cout.width(2);
cout.fill('0');
cout << (now->tm_mon + 1) << '-';
cout.width(2);
cout.fill('0');
cout << now->tm_mday;
return 0;
}
설명 |
ctime 헤더의 time_t 타입에 현재의 시간을 저장하고,
tm 구조체를 이용하여 연-월-일 형식으로 출력한다.
'PS > BOJ' 카테고리의 다른 글
[C++] BOJ (백준) 25083 : 새싹 (0) | 2022.08.30 |
---|---|
[C++] BOJ (백준) 10172 : 개 (0) | 2022.08.30 |
[C++] BOJ (백준) 10171 : 고양이 (0) | 2022.08.30 |
[C++] BOJ (백준) 7287 : 등록 (0) | 2022.08.30 |
[C++] BOJ (백준) 2557 : Hello World (0) | 2022.08.30 |