简单字符串排序问题。
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int SIZE = 101;
struct index
{
char str[16];
int beg, end;
}a[SIZE];
int cmp1(const void *a, const void *b)
{
index *p1 = (index*)a;
index *p2 = (index*)b;
return p1->beg > p2->beg? 1:-1;
}
int cmp2(const void *a, const void *b)
{
index *p1 = (index*)a;
index *p2 = (index*)b;
return p2->end > p1->end? 1:-1;
}
int main()
{
int T;
int i, j;
scanf("%d", &T);
while(T--)
{
int n;
int h, m, s;
int h1, m1, s1;
scanf("%d", &n);
getchar();
memset(a, 0, sizeof(a));
for(i = 0 ; i < n ; i++)
{
scanf("%s", a[i].str);
scanf("%d:%d:%d", &h, &m, &s);
a[i].beg = 3600*h+60*m+s;
scanf("%d:%d:%d", &h1, &m1, &s1);
a[i].end = 3600*h1+60*m1+s1;
}
qsort(a, n, sizeof(a[0]), cmp1);
printf("%s ", a[0].str);
qsort(a, n, sizeof(a[0]), cmp2);
printf("%s\n", a[0].str);
}
return 0;
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int SIZE = 101;
struct index
{
char str[16];
int beg, end;
}a[SIZE];
int cmp1(const void *a, const void *b)
{
index *p1 = (index*)a;
index *p2 = (index*)b;
return p1->beg > p2->beg? 1:-1;
}
int cmp2(const void *a, const void *b)
{
index *p1 = (index*)a;
index *p2 = (index*)b;
return p2->end > p1->end? 1:-1;
}
int main()
{
int T;
int i, j;
scanf("%d", &T);
while(T--)
{
int n;
int h, m, s;
int h1, m1, s1;
scanf("%d", &n);
getchar();
memset(a, 0, sizeof(a));
for(i = 0 ; i < n ; i++)
{
scanf("%s", a[i].str);
scanf("%d:%d:%d", &h, &m, &s);
a[i].beg = 3600*h+60*m+s;
scanf("%d:%d:%d", &h1, &m1, &s1);
a[i].end = 3600*h1+60*m1+s1;
}
qsort(a, n, sizeof(a[0]), cmp1);
printf("%s ", a[0].str);
qsort(a, n, sizeof(a[0]), cmp2);
printf("%s\n", a[0].str);
}
return 0;
}