끄적끄적 코딩
article thumbnail

오늘 날짜를 출력하는 문제입니다.

 

#include <iostream>
#include <string>
#include <ctime>
using namespace std;

int main(int argc, char *argv[]) {
	struct tm *t;
	string s = "";
	time_t timer;
	timer = time(NULL);
	
	t = localtime(&timer);
	s += to_string(t->tm_year + 1900);
	s += "-";
	if (t->tm_mon + 1 < 10) {
		s += "0";
	}
	s += to_string(t->tm_mon + 1);
	s += "-";
	if (t->tm_mday + 1 < 10) {
		s += "0";
	}
	s += to_string(t->tm_mday);
	
	cout << s << endl;

	return 0;
}

'알고리즘' 카테고리의 다른 글

[C++] 백준 2522번 별 찍기 - 12  (2) 2019.10.01
[C++] 백준 10451번 순열 사이클  (0) 2019.09.30
[C++] 백준 1547번 공  (0) 2019.09.28
[C++] 백준 16360번 Go Latin  (0) 2019.09.27
[C++] 백준 2914번 저작권  (0) 2019.09.27

검색 태그