C++ 日期排序算法实现
#include
struct Date { int year, month, day; };
bool cmp(Date a, Date b) { if (a.year != b.year) { return a.year < b.year; } else if (a.month != b.month) { return a.month < b.month; } else { return a.day < b.day; } }
int main() { int n; cin >> n; Date dates[n]; for (int i = 0; i < n; i++) { cin >> dates[i].year >> dates[i].month >> dates[i].day; } sort(dates, dates + n, cmp); for (int i = 0; i < n; i++) { cout << dates[i].year << ' ' << dates[i].month << ' ' << dates[i].day << endl; } return 0; }
原文地址: https://www.cveoy.top/t/topic/oFYQ 著作权归作者所有。请勿转载和采集!