알고리즘
[C++] 백준 10699번 오늘 날짜
J3SUNG
2019. 9. 28. 16:53
728x90
오늘 날짜를 출력하는 문제입니다.
#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;
}