标签:des style class blog c code
3 1 000007 James 85 000010 Amy 90 000001 Zoe 60 4 2 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 98 4 3 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 90 0 0
Case 1: 000001 Zoe 60 000007 James 85 000010 Amy 90 Case 2: 000010 Amy 90 000002 James 98 000007 James 85 000001 Zoe 60 Case 3: 000001 Zoe 60 000007 James 85 000002 James 90 000010 Amy 90
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 typedef struct 5 { 6 int ID; 7 char num[10],name[10]; 8 9 }USER; 10 USER Student[100005]; 11 12 void quick_sort1(USER s[],int l,int r) 13 { 14 if(l<r) 15 { 16 int i=l,j=r,ID; 17 char x[10],name[10]; 18 strcpy(x,s[l].num); 19 strcpy(name,s[l].name); 20 ID=s[l].ID; 21 while (i<j) 22 { 23 while(i<j&&strcmp(s[j].num,x)>=0) 24 j--; 25 if(i<j) 26 s[i++]=s[j]; 27 while(i<j&&strcmp(s[i].num,x)<=0) 28 i++; 29 if(i<j) 30 s[j--]=s[i]; 31 } 32 strcpy(s[i].num,x); 33 strcpy(s[i].name,name); 34 s[i].ID=ID; 35 quick_sort1(s,l,i-1); 36 quick_sort1(s,i+1,r); 37 } 38 } 39 40 void quick_sort2(USER s[],int l,int r) 41 { 42 if(l<r) 43 { 44 int i=l,j=r,ID; 45 char x[10],num[10]; 46 strcpy(num,s[l].num); 47 strcpy(x,s[l].name); 48 ID=s[l].ID; 49 while (i<j) 50 { 51 while(i<j&&strcmp(s[j].name,x)>=0) 52 { 53 if(strcmp(s[j].name,x)==0&&strcmp(s[j].num,num)<0) 54 break; 55 j--; 56 } 57 if(i<j) 58 s[i++]=s[j]; 59 while(i<j&&strcmp(s[i].name,x)<=0) 60 { 61 if(strcmp(s[i].name,x)==0&&strcmp(s[i].num,num)>0) 62 break; 63 i++; 64 } 65 if(i<j) 66 s[j--]=s[i]; 67 } 68 strcpy(s[i].num,num); 69 strcpy(s[i].name,x); 70 s[i].ID=ID; 71 quick_sort2(s,l,i-1); 72 quick_sort2(s,i+1,r); 73 } 74 } 75 76 void quick_sort3(USER s[],int l,int r) 77 { 78 if(l<r) 79 { 80 int i=l,j=r,ID; 81 char name[10],num[10]; 82 strcpy(num,s[i].num); 83 strcpy(name,s[i].name); 84 ID=s[i].ID; 85 while (i<j) 86 { 87 while(i<j&&s[j].ID>=ID) 88 { 89 if(s[j].ID==ID&&strcmp(s[j].num,num)<0) 90 break; 91 j--; 92 } 93 if(i<j) 94 s[i++]=s[j]; 95 while(i<j&&s[i].ID<=ID) 96 { 97 if(s[i].ID==ID&&strcmp(s[i].num,num)>0) 98 break; 99 i++; 100 } 101 if(i<j) 102 s[j--]=s[i]; 103 } 104 s[i].ID=ID; 105 strcpy(s[i].name,name); 106 strcpy(s[i].num,num); 107 quick_sort3(s,l,i-1); 108 quick_sort3(s,i+1,r); 109 } 110 } 111 112 int main() 113 { 114 int N,i,change,times; 115 times=1; 116 while(scanf("%d %d",&N,&change),N) 117 { 118 for(i=0;i<N;i++) 119 scanf("%s %s %d",Student[i].num,Student[i].name,&Student[i].ID); 120 switch(change) 121 { 122 case 1:quick_sort1(Student,0,i-1);break; 123 case 2:quick_sort2(Student,0,i-1);break; 124 case 3:quick_sort3(Student,0,i-1);break; 125 } 126 printf("Case %d:\n",times++); 127 for(i=0;i<N;i++) 128 printf("%s %s %d\n",Student[i].num,Student[i].name,Student[i].ID); 129 } 130 return 0; 131 }
标签:des style class blog c code
原文地址:http://www.cnblogs.com/LWF5201314614/p/3750318.html