01 #include<iostream>
02 #include<cstdlib>
03 #define max 1001
04 char name[max][16];
05 char start[max][6];
06 char end[max][6];
07 using namespace std ;
08 void Quicksort(int *p,int* q,int* shunxun ,int n,int m)
09 {
10 int Partion(int *,int *,int*,int,int);
11 if(n<m)
12 {
13 int k = Partion(p,q,shunxun,n,m);
14 Quicksort(p,q,shunxun,n,k-1);
15 Quicksort(p,q,shunxun,k+1,m);
16 }
17 }
18 int Partion(int* p,int* q,int* shunxun,int n,int m)
19 {
20 void Swap(int* ,int,int);
21 int flag = p[m];
22 int i = n-1 ;
23 for(int j=n;j<m;j++)
24 if(p[j]<flag)
25 {
26 i++;
27 Swap(p,j,i);
28 Swap(q,j,i);
29 Swap(shunxun,j,i);
30 }
31 Swap(p,i+1,m);
32 Swap(q,i+1,m);
33 Swap(shunxun,i+1,m);
34 return i+1;
35 }
36 void Swap(int* p,int i,int j)
37 {
38 int temp;
39 temp = p[i];
40 p[i]=p[j];
41 p[j]=temp;
42 }
43 int main()
44 {
45 int n ;
46 int number = 0 ;
47 cin>>n;
48 for(int i=0;i<n;i++)
49 {
50 cin>>name[i];
51 cin>>start[i];
52 cin>>end[i];
53 }
54 int* starttime= new int[n];
55 int* endtime= new int[n];
56 int* que = new int[n];
57 int* shunxun = new int[n];
58 for(int i=0;i<n;i++)
59 {
60 starttime[i]=(start[i][0]-’0′)*1000+100*(start[i][1]-’0′)+10*(start[i][3]-’0′)+(start[i][4]-’0′);
61 endtime[i]=1000*(end[i][0]-’0′)+100*(end[i][1]-’0′)+10*(end[i][3]-’0′)+(end[i][4]-’0′);
62 shunxun[i]=i;
63 }
64 Quicksort(endtime,starttime,shunxun,0,n-1);
65 int Cendtime=endtime[0];
66 que[0]=shunxun[0];
67 for(int j=1;j<n;j++)
68 if(starttime[j]>=Cendtime)
69 {
70 number++;
71 que[number]=shunxun[j];
72 Cendtime= endtime[j];
73 }
74 cout<<number+1<<endl;
75 for(int j=0;j<number+1;j++)
76 cout<<name[que[j]]<<" ";
77 cout<<endl;
78 delete[] starttime,endtime,que,shunxun;
79 system("pause");
80 return 0 ;
81 }
|