编程题:
1、给出一组日期,输出离今天最远的日期
#include<iostream>
#include <ctime>
using namespace std;
int main() {
struct tm t1 = {0};
struct tm t2 = {0};
struct tm now = {0};
double second1, second2;
t1.tm_year = 2040 - 1900;
t1.tm_mon = 6;
t1.tm_mday = 23;
t2.tm_year = 2011 - 1900;
t2.tm_mon = 6;
t2.tm_mday = 23;
now.tm_year = 2021 - 1900;
now.tm_mon = 12;
now.tm_mday = 25;
second1 = difftime(mktime(&now), mktime(&t1));
second2 = difftime(mktime(&now), mktime(&t2));
if (abs(second1) > abs(second2)) {
cout << "距离今天最远的日期是:" << endl;
cout << "年: " << 1900 + t1.tm_year << endl;
cout << "月: " << 1 + t1.tm_mon << endl;
cout << "日: " << t1.tm_mday << endl;
} else {
cout <&l