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.
76 lines
1.7 KiB
76 lines
1.7 KiB
#include <stdio.h>
|
|
#include <string.h>
|
|
typedef struct Student{
|
|
char id[100];
|
|
int cl;
|
|
char name[100];
|
|
float score1;
|
|
float score2;
|
|
float score3;
|
|
float total_score;
|
|
}Student;
|
|
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 judgenew(Student student[],int *n,char *id_or_name){
|
|
int i;
|
|
for(i=0;i<*n;i++){
|
|
if(strcmp(student[i].id,id_or_name)==0||strcmp(student[i].name,id_or_name)==0){
|
|
break;
|
|
}
|
|
}
|
|
if(i==*n){
|
|
print_students(student,n);
|
|
}else{
|
|
for(;i<*n-1;i++) {
|
|
student[i]=student[i+1];
|
|
}
|
|
(*n)--;
|
|
}
|
|
}
|
|
void print_students(Student student[],int n) {
|
|
int i;
|
|
for(i=0;i<n;i++) {
|
|
if(student[i].id[0] != '\0')
|
|
printf("%s %d %s %.1f %.1f %.1f\n", student[i].id,student[i].cl,student[i].name,student[i].score1,student[i].score2,student[i].score3);
|
|
}
|
|
}
|
|
void deletestudentinfo(char a,Student student[],int n){
|
|
if(a=='n'){
|
|
sort(student,n);
|
|
print_students(student,n);
|
|
}else if(a=='y'){
|
|
return;
|
|
}
|
|
}
|
|
int main(){
|
|
Student student[3] = {
|
|
{"10001", 11, "Zhang", 99.5, 88.5, 89.5, 99.5+88.5+89.5},
|
|
{"10002", 12, "Yang", 77.9, 56.5, 87.5, 77.9+56.5+87.5},
|
|
{"10003", 11, "Liang", 92.5, 99.0, 60.5, 92.5+99.0+60.5},
|
|
};
|
|
int n=3;
|
|
char id_or_name[100];
|
|
sort(student, n);
|
|
|
|
scanf("%s",id_or_name);
|
|
printf("Are you sure(yes/no)?\n");
|
|
|
|
getchar();
|
|
char a;
|
|
scanf("%c",&a);
|
|
|
|
judgenew(student,&n,id_or_name);
|
|
deletestudentinfo(a,student,n);
|
|
|
|
return 0;
|
|
} |