题目描述:https://pycoder.blog.csdn.net/article/details/124677562
非常好用的qsort
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
struct Node {
int year;
int month;
int date;
int hours;
int minute;
int second;
int ms;
};
int myCmp(const void *a, const void *b)
{
struct Node *aa = (struct Node *)a;
struct Node *bb = (struct Node *)b;
if (aa->year != bb->year) return aa->year - bb->year;
if (aa->month != bb->month) return aa->month - bb->month;
if (aa->date != bb->date) return aa->date - bb->date;
if (aa->hours != bb->hours) return aa->hours - bb->hours;
if (aa->minute != bb->minute) return aa->minute - bb->minute;
if (aa->second != bb->second) return aa->second - bb->second;
if (aa->ms != bb->ms) return aa->ms - bb->ms;
return 0;
}
int main(void)
{
int n;
char str[100] = {0};
int index = 0;
struct Node node[1000];
int res = 0;
scanf("%d", &n);
getchar();
for (int i = 0; i < n; i++) {
gets(str);
sscanf(str, "%d-%d-%d %d:%d:%d.%d", &node[index].year, &node[index].month, &node[index].date,
&node[index].hours, &node[index].minute, &node[index].second, &node[index].ms);
index++;
}
qsort(node, index, sizeof(node[0]), myCmp);
struct Node pre = node[0];
res = 1;
for (int i = 1; i < index; i++) {
if (node[i].year != pre.year) goto lable;
if (node[i].month != pre.month) goto lable;
if (node[i].date != pre.date) goto lable;
if (node[i].hours != pre.hours) goto lable;
if (node[i].minute != pre.minute) goto lable;
if (node[i].second != pre.second) goto lable;
if (node[i].ms == pre.ms) goto lable;
continue;
lable:
pre = node[i];
res++;
}
printf("%d\n", res);
return 0;
}