You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.3 KiB

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
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);//<2F><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ʱ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
sprintf(temp3,"%d",p3);
for(i=0; i<numStudents; i++){
students[i].total_score = students[i].score1 + students[i].score2 + students[i].score3;
switch(type){
case 1:
if(students[i].cl>=p1&&students[i].cl<=p2){
results[(*numResults)++] = students[i];//<2F><EFBFBD><E0BCB6><EFBFBD><EFBFBD>p1-p2<70><32>
}
break;
case 2:
if(strcmp(students[i].id,temp1)>=0 && strcmp(students[i].id,temp2)<=0){
results[(*numResults)++] = students[i];//ѧ<><D1A7><EFBFBD><EFBFBD>p1-p2<70><32>
}
break;
case 3:
if(students[i].name[0]==p1){
results[(*numResults)++] = students[i];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>ĸ<EFBFBD><C4B8>ͷ<EFBFBD><CDB7>ѧ<EFBFBD><D1A7>
}
break;
case 4:
if(students[i].total_score>=p1){
results[(*numResults)++] = students[i];//<2F>ִܷ<DCB7><D6B4>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>
}
break;
case 5:
if(students[i].cl==p1 && strcmp(students[i].id,temp2)>=0 && strcmp(students[i].id,temp3)<= 0){
results[(*numResults)++] = students[i];//<2F>ض<EFBFBD><D8B6><EFBFBD><E0BCB6><EFBFBD>ض<EFBFBD>ѧ<EFBFBD>ŷ<EFBFBD>Χ<EFBFBD><CEA7>ѧ<EFBFBD><D1A7>
}
break;
}
}
}
void sort(Student student[],int n){
int i,j;
for(i=0;i<n-1;i++){
for(j=0;j<n-1-i;j++){
if(student[j].cl>student[j + 1].cl||(student[j].cl==student[j + 1].cl&&student[j].total_score<student[j + 1].total_score)){
Student temp=student[j];
student[j]=student[j+1];
student[j+1]=temp;
}
}
}
}
void printResults(Student *results, int numResults){
int i;
for(i=0; i<numResults; i++){
printf("%s %d %s %.1f %.1f %.1f\n", results[i].id, results[i].cl, results[i].name, results[i].score1, results[i].score2, results[i].score3);
}
}
int main(){
Student students[7] = {
// <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{"10001", 11, "Zhang", 99.5, 88.5, 89.5},
{"10002", 12, "Yang", 77.9, 56.5, 87.5},
{"10003", 11, "Liang", 92.5, 99.0, 60.5},
{"10004", 11, "Cai", 89.6, 56.9, 90.5},
{"10005", 14, "Fu", 55.6, 67.9, 98.9},
{"10006", 12, "Mao", 22.1, 45.9, 99.2},
{"10007", 13, "Zhan", 35.6, 67.9, 88.0}
};
int type;
int p1,p2,p3;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ֵ<><D6B5><EFBFBD><EFBFBD>");
getinput(&type,&p1,&p2,&p3);
Student results[7];
int numResults;
query(students,7,type,p1,p2,p3,results,&numResults);
sort(results,numResults);
printResults(results,numResults);
return 0;
}