【HDOJ】1234 开门人和关门人

大水题,没想到还有人错。

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 
 5 #define MAXNUM 1005
 6 
 7 typedef struct {
 8     char id[20];
 9     char in_t[15];
10     char out_t[15];
11 } person_st;
12 
13 person_st persons[MAXNUM];
14 
15 typedef struct {
16     int index;
17     int secs;
18 } secs_st;
19 
20 secs_st in_secs[MAXNUM];
21 secs_st out_secs[MAXNUM];
22 
23 int comp(const void *a, const void *b) {
24     return ((secs_st *)a)->secs - ((secs_st *)b)->secs;
25 }
26 
27 int calsec(char time[]) {
28     int i, j, tmp;
29     int hour, min, sec;
30 
31     j = tmp = 0;
32     for (i=0; i<strlen(time); ++i) {
33         if (time[i] == ':') {
34             if (j==0) hour = tmp;
35             if (j==1) min  = tmp;
36             tmp = 0;
37             j++;
38         } else {
39             tmp = 10*tmp + time[i]-'0';
40         }
41     }
42     sec = tmp;
43 
44     return hour*3600+min*60+sec;
45 }
46 
47 int main() {
48     int case_n, n;
49     int i;
50 
51     scanf("%d", &case_n);
52 
53     while (case_n--) {
54         scanf("%d", &n);
55         for (i=0; i<n; ++i) {
56             getchar();
57             scanf("%s %s %s", persons[i].id, persons[i].in_t, persons[i].out_t);
58             in_secs[i].secs = calsec(persons[i].in_t);
59             out_secs[i].secs = calsec(persons[i].out_t);
60             in_secs[i].index = out_secs[i].index = i;
61         }
62 
63         qsort(in_secs, n, sizeof(secs_st), comp);
64         qsort(out_secs, n, sizeof(secs_st), comp);
65         printf("%s %s\n", persons[in_secs[0].index].id, persons[out_secs[n-1].index].id);
66     }
67 
68     return 0;
69 }

 

posted on 2014-03-22 22:12  Bombe  阅读(155)  评论(0编辑  收藏  举报

导航