diff --git a/作业2.7.c b/作业2.7.c new file mode 100644 index 0000000..bcb5f85 --- /dev/null +++ b/作业2.7.c @@ -0,0 +1,106 @@ +#include +#include +#include +typedef struct Student{ + char id[100]; + int cl; + char name[100]; + float score1; + float score2; + float score3; + float total_score; +}Student; +void getinput(int *type,int *p1,int *p2,int *p3){ + scanf("%d",type); + if(*type==1||*type==2){ + scanf("%d-%d",p1,p2); + }else if(*type==3){ + char temp[20]; + scanf("%s",temp); + *p1=temp[0]; + }else if(*type==5){ + scanf("%d.%d-%d",p1,p2,p3); + }else{ + scanf("%d",p1); + } +} +void query(Student *students,int numStudents,int type,int p1,int p2,int p3,Student *results,int *numResults){ + int i; + *numResults = 0; + char temp1[20], temp2[20],temp3[20]; + sprintf(temp1, "%d", p1); + sprintf(temp2, "%d", p2);//¸ñʽ»¯Êý¾ÝдÈëÁÙʱ×Ö·û´® + sprintf(temp3,"%d",p3); + for(i=0; i=p1&&students[i].cl<=p2){ + results[(*numResults)++] = students[i];//°à¼¶ºÅÔÚp1-p2ÄÚ + } + break; + case 2: + if(strcmp(students[i].id,temp1)>=0 && strcmp(students[i].id,temp2)<=0){ + results[(*numResults)++] = students[i];//ѧºÅÔÚp1-p2ÄÚ + } + break; + case 3: + if(students[i].name[0]==p1){ + results[(*numResults)++] = students[i];//Ãû×ÖÒÔÌض¨×Öĸ¿ªÍ·µÄѧÉú + } + break; + case 4: + if(students[i].total_score>=p1){ + results[(*numResults)++] = students[i];//×Ü·Ö´óÓÚµÈÓÚÌض¨·ÖÊýµÄѧÉú + } + break; + case 5: + if(students[i].cl==p1 && strcmp(students[i].id,temp2)>=0 && strcmp(students[i].id,temp3)<= 0){ + results[(*numResults)++] = students[i];//Ìض¨°à¼¶¡¢Ìض¨Ñ§ºÅ·¶Î§µÄѧÉú + } + break; + } + } +} +void sort(Student student[],int n){ + int i,j; + for(i=0;istudent[j + 1].cl||(student[j].cl==student[j + 1].cl&&student[j].total_score