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.

98 lines
2.7 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student{
char stunumber[5];
int class;
char name[10];
float grade1;
float grade2;
float grade3;
float sum;
}students[3]={{"10001",11,"Zhang",99.5,88.5,89.5,99.5+88.5+99.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}};
void selection_sort(struct Student arr[], int n) {
int i, j, min_idx;
//һһ<D2BB><D2BB><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD>class<73><73>ֵ
for (i = 0; i < n-1; i++) {
// <20>ҵ<EFBFBD><D2B5><EFBFBD>Сֵ<D0A1><D6B5>λ<EFBFBD><CEBB>
min_idx = i;
for (j = i+1; j < n; j++)
{
if (arr[j].class < arr[min_idx].class)
{
min_idx = j;
}
else if(arr[j].class == arr[min_idx].class)
{
if(arr[j].sum > arr[min_idx].sum)
{
min_idx=j;
}
}
}
// ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
struct Student temp = arr[min_idx];
arr[min_idx] = arr[i];
arr[i] = temp;
}
}
int main(){
int n=3;
void selection_sort(struct Student arr[], int n);
int idx=-1;//<2F><><EFBFBD>Ҵ<EFBFBD><D2B4>޸<EFBFBD>ѧ<EFBFBD><D1A7>
char num_or_name[10];
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>޸ĵ<EFBFBD>ѧ<EFBFBD><EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
scanf("%s",&num_or_name);
for(int i=0;i<3;i++)//<2F><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>
{
if(strcmp(num_or_name, students[i].stunumber) == 0 || strcmp(num_or_name, students[i].name) == 0){
idx=i;
printf("idx is:%d\n",idx);
break;
}
}
if(idx==-1)//ѧ<><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
printf("δ<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>!\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>!\n");
for(int i=0;i < 3;i++)
{
printf("%s %d %s %.1f %.1f %.1f \n", students[i].stunumber, students[i].class, students[i].name, students[i].grade1, students[i].grade2, students[i].grade3);
}
return 0;
}
printf("<EFBFBD>Ѳ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>!\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ\n");
struct Student temp;//ѧ<><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ĺ<DEB8><C4BA><EFBFBD><EFBFBD><EFBFBD>Ϣ
scanf("%s %d %s %f %f %f",&temp.stunumber,&temp.class,&temp.name,&temp.grade1,&temp.grade2,&temp.grade3);
temp.sum=temp.grade1+temp.grade2+temp.grade3;
students[idx]=temp;
selection_sort(students,3);//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD>޸ĺ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
int class0=0;
for(int i=0;i < 3;i++){
printf("\n");
if(students[i].class==class0)
{
printf(" %s %d %s %.1f %.1f %.1f ", students[i].stunumber, students[i].class, students[i].name, students[i].grade1, students[i].grade2, students[i].grade3);
}
if(class0!=students[i].class){
class0=students[i].class;
printf("%d ",class0);
printf("%s %d %s %.1f %.1f %.1f ", students[i].stunumber, students[i].class, students[i].name, students[i].grade1, students[i].grade2, students[i].grade3);
}
if(strcmp(num_or_name, students[i].stunumber) == 0 || strcmp(num_or_name, students[i].name) == 0)
{
printf("modifiled");
}
}
}