level 2
5945040
楼主
#include<stdio.h>
#include<stdlib.h>
#define N 8
typedef struct
{
char stuid[12]; //student id
int s; //score
}STREC;
void fun(STREC sc[]){
STREC tmp; int max;
for(int i = 0; i < N-1; i++){
max = i;
for(int j = i; j < N; j++)
if(sc[j].s > sc[i].s) max = j;
tmp = sc[i];
sc[i] = sc[max];
sc[max] = tmp;
}
}
int main(void){
STREC s[N]={ {"201901",189},{"201902",199},{"201903",87},{"201904",69},{"201905",36},{"201906",49}{"201907",88},{"201908",120}
};
fun(s);
printf("After Sorted:\n");
for(int i = 0; i < N; i++){
if(i%4==0) printf("\n");
printf(" %6s:%4d ",s[i].stuid,s[i].s);
}
printf("\n");
system("pause");
return 0;
}
2019年08月06日 10点08分
1
#include<stdlib.h>
#define N 8
typedef struct
{
char stuid[12]; //student id
int s; //score
}STREC;
void fun(STREC sc[]){
STREC tmp; int max;
for(int i = 0; i < N-1; i++){
max = i;
for(int j = i; j < N; j++)
if(sc[j].s > sc[i].s) max = j;
tmp = sc[i];
sc[i] = sc[max];
sc[max] = tmp;
}
}
int main(void){
STREC s[N]={ {"201901",189},{"201902",199},{"201903",87},{"201904",69},{"201905",36},{"201906",49}{"201907",88},{"201908",120}
};
fun(s);
printf("After Sorted:\n");
for(int i = 0; i < N; i++){
if(i%4==0) printf("\n");
printf(" %6s:%4d ",s[i].stuid,s[i].s);
}
printf("\n");
system("pause");
return 0;
}