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.

116 lines
3.8 KiB

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int num1=0,num2=0;//<2F><><EFBFBD><EFBFBD>2,5<>б<EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD>ѧ<EFBFBD><D1A7>
int clas=0;//5<>а<D0B0><E0BCB6>
int clas1=0,clas2=0;//1<><31><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><D2BC>ް<EFBFBD><DEB0><EFBFBD>
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><E1B9B9>
struct Student {
int student_id;
int class_id;
char name[20];
double score1;
double score2;
double score3;
};
// <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
struct Student student_data[] = {
{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}
};
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int student_count = sizeof(student_data) / sizeof(student_data[0]);
// <20>ȽϺ<C8BD><CFBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD><DAB0><EFBFBD><E0BCB6>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><E0BCB6><EFBFBD>ܳɼ<DCB3><C9BC>Ӵ<EFBFBD><D3B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
int compare_students(const void *a, const void *b) {
struct Student *student1 = (struct Student *)a;
struct Student *student2 = (struct Student *)b;
if (student1->class_id != student2->class_id) {
return student1->class_id - student2->class_id;
} else {
double total1 = student1->score1 + student1->score2 + student1->score3;
double total2 = student2->score1 + student2->score2 + student2->score3;
return (total2 - total1) > 0 ? 1 : -1;
}
}
// <20><>ѯѧ<D1AF><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
void query_students(int query_type, char *query_value) {
for (int i = 0; i < student_count; i++) {
struct Student student = student_data[i];
double total = student.score1 + student.score2 + student.score3;
if (query_type == 1 && student.class_id >= clas1 && student.class_id <= clas2) {
printf("%d %d %s %.1lf %.1lf %.1lf\n", student.student_id, student.class_id, student.name, student.score1, student.score2, student.score3);
} else if (query_type == 2 && student.student_id >= num1 && student.student_id <= num2) {
printf("%d %d %s %.1lf %.1lf %.1lf\n", student.student_id, student.class_id, student.name, student.score1, student.score2, student.score3);
} else if (query_type == 3 && strncmp(student.name, query_value, strlen(query_value)-1) == 0) {
printf("%d %d %s %.1lf %.1lf %.1lf\n", student.student_id, student.class_id, student.name, student.score1, student.score2, student.score3);
} else if (query_type == 4 && total >= atof(query_value)) {
printf("%d %d %s %.1lf %.1lf %.1lf\n", student.student_id, student.class_id, student.name, student.score1, student.score2, student.score3);
} else if (query_type == 5 && student.class_id == clas && student.student_id >= num1 && student.student_id <= num2) {
printf("%d %d %s %.1lf %.1lf %.1lf\n", student.student_id, student.class_id, student.name, student.score1, student.score2, student.score3);
}
}
}
int main() {
int query_type;
char query_value[20];
int i;
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>");
scanf("%d %s", &query_type, query_value);//(1,2,3,4,5)
//<2F><>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD>
if(query_type==1){
for(i=0;i<2;i++){
clas1=clas1*10+query_value[i]-'0';
}
for(i=3;i<5;i++){
clas2=clas2*10+query_value[i]-'0';
}
}
//<2F><>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD>
if(query_type==2){
for(i=0;i<5;i++){
num1=num1*10+query_value[i]-'0';
}
for(i=6;i<11;i++){
num2=num2*10+query_value[i]-'0';
}
}
//<2F><>5<EFBFBD>и<EFBFBD><D0B8><EFBFBD>
if(query_type==5){
for(i=0;i<2;i++){
clas=clas*10+query_value[i]-'0';
}
for(i=3;i<8;i++){
num1=num1*10+query_value[i]-'0';
}
for(i=9;i<14;i++){
num2=num2*10+query_value[i]-'0';
}
}
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
qsort(student_data, student_count, sizeof(struct Student), compare_students);
// <20><>ѯѧ<D1AF><D1A7><EFBFBD><EFBFBD>Ϣ
query_students(query_type, query_value);
return 0;
}