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.
86 lines
2.4 KiB
86 lines
2.4 KiB
1 year ago
|
#include <stdio.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <string.h>
|
||
|
#define NAME 20
|
||
|
#define SIZE 3
|
||
|
struct student
|
||
|
{
|
||
|
int id;
|
||
|
int class;
|
||
|
char name[NAME];
|
||
|
float score_math;
|
||
|
float score_phi;
|
||
|
float score_eng;
|
||
|
bool ismodified;
|
||
|
};
|
||
|
|
||
|
|
||
|
void update(struct student a[],int count){
|
||
|
struct student temp;
|
||
|
scanf("%d %d %s %f %f %f",&temp.id,&temp.class,&temp.name,&temp.score_math,&temp.score_phi,&temp.score_eng);
|
||
|
for(int i = 0;i<count;i++){
|
||
|
if(a[i].id == temp.id){
|
||
|
a[i] = temp;
|
||
|
a[i].ismodified = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void sort(struct student a[],int count){
|
||
|
struct student temp;
|
||
|
for(int i = 0;i < count-1;i++){
|
||
|
for(int j = i+1;j<count-1;j++){
|
||
|
if(a[j].class > a[j+1].class){
|
||
|
temp = a[j];
|
||
|
a[j] = a[j+1];
|
||
|
a[j+1] = temp;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for (int m = 0; m < count-1; m++) {
|
||
|
for (int n = m + 1; n < count-1; n++) {
|
||
|
if (a[n].class == a[n+1].class) {
|
||
|
float sum1 = a[n].score_math + a[n].score_phi + a[n].score_eng;
|
||
|
float sum2 = a[n+1].score_math + a[n+1].score_phi + a[n+1].score_eng;
|
||
|
if (sum1 < sum2 || (sum1 == sum2 && a[m].id > a[n].id)) {
|
||
|
struct student temp = a[n];
|
||
|
a[n] = a[n+1];
|
||
|
a[n+1] = temp;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
void printgrade(struct student a[],int count){
|
||
|
for(int i = 0;i<count;i++){
|
||
|
if(i == 0)
|
||
|
printf("%d %d %s %.1f %.1f %.1f",a[i].class,a[i].id,a[i].name,a[i].score_math,a[i].score_phi,a[i].score_eng);
|
||
|
else{
|
||
|
if(a[i].class == a[i-1].class){
|
||
|
printf(" %d %s %.1f %.1f %.1f",a[i].id,a[i].name,a[i].score_math,a[i].score_phi,a[i].score_eng);
|
||
|
}
|
||
|
else{
|
||
|
printf("%d %d %s %.1f %.1f %.1f",a[i].class,a[i].id,a[i].name,a[i].score_math,a[i].score_phi,a[i].score_eng);
|
||
|
}
|
||
|
}
|
||
|
if(a[i].ismodified){
|
||
|
printf(" modified\n");
|
||
|
}
|
||
|
else{
|
||
|
printf("\n");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
int main(){
|
||
|
struct student grade[SIZE]={
|
||
|
{10001,11,"Zhang",99.5,88.5,89.5,false},
|
||
|
{10002,12,"Yang",77.9,56.5,87.5,false},
|
||
|
{10003,11,"Liang",92.5,99.0,60.5,false}
|
||
|
};
|
||
|
int count = SIZE;
|
||
|
update(grade,count);
|
||
|
sort(grade,count);
|
||
|
printgrade(grade,count);
|
||
|
return 0;
|
||
|
}
|