文章
145
粉丝
217
获赞
21
访问
84.9k
#include <stdio.h>
#define N 1000
#define M 10
typedef struct{
char Sno[N];
int s;
}Student;
//按排序(冒泡排序:稳定)
void Sort(Student stu[],int n,int b)
{
Student temp;
int i,j;
for(i = 0; i < n-1; i++)
for(j = 1; j < n-i; j++)
if(b == 1)//升序
{
if(stu[j-1].s > stu[j].s)
{
temp = stu[j];
stu[j] = stu[j-1];
stu[j-1] = temp;
}
}
else {//降序
if(stu[j-1].s < stu[j].s)
{
temp = stu[j];
stu[j] = stu[j-1];
stu[j-1] = temp;
}
}
}
int main() {
Student stu[N];
int a, b, i,j = 0;
while (scanf("%d %d", &a, &b) != EOF) {
for(i = 0; i < a; i++)
scanf("%s %d",stu[i].Sno,&stu[i].s);
Sort(stu,a...
登录后发布评论
暂无评论,来抢沙发