#include <stdio.h>
#include <stdlib.h>
struct student
{
int number;
int score;
};
int main()
{
struct student students[101];
int n, i, j;
struct student temp;
while(scanf("%d",&n) != EOF)
{
//接收数据
for(i = 0; i < n; i++)
{
scanf("%d%d",&students[i].number,&students[i].score);
}
//冒泡排序
for(i = 0; i < n - 1; i ++)
{
for(j = 0; j < n - i - 1; j ++)
{
if(students[j].score > students[j + 1].score)
{
temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}else if(students[j].score == students[j + 1].score)
{
if(students[j].number > students[j + 1].number)
{
temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
}
//输出排序结果
for(i = 0; i < n; i ++)
{
printf("%d %d\n",students[i].number,students[i].score);
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student{
char name[101];
int age;
int grade;
};
int partition(struct student *A, int left, int right);
void quicksort(struct student *A, int begin, int end);
int main()
{
struct student students[1001];
int i, n;
while(scanf("%d",&n) != EOF)
{
//学生成绩赋值
for(i = 0; i < n; i ++)
{
scanf("%s%d%d",students[i].name, &students[i].age, &students[i].grade);
}
//快速排序
quicksort(students, 0, n-1);
//打印输出
for(i = 0; i < n; i ++)
{
printf("%s %d %d\n",students[i].name, students[i].age, students[i].grade);
}
}
return 0;
}
void quicksort(struct student *A, int begin, int end)
{
int pivot;
if(begin < end)
{
pivot = partition(A, begin, end);
quicksort(A, begin, pivot - 1);
quicksort(A, pivot + 1, end);
}
}
int partition(struct student *A, int left, int right)
{
struct student stand = A[left];
while(left < right)
{
while(left < right && (A[right].grade > stand.grade || (A[right].grade == stand.grade && strcmp(A[right].name,stand.name) > 0) || (A[right].grade == stand.grade && strcmp(A[right].name,stand.name) == 0 && A[right].age > stand.age ) ) )
{
right --;
}
if(left < right)
{
A[left ++] = A[right];
}
while(left < right && (A[left].grade < stand.grade || (A[left].grade == stand.grade && strcmp(A[left].name,stand.name) < 0) || (A[left].grade == stand.grade && strcmp(A[left].name,stand.name) == 0 && A[left].age < stand.age ) ) )
{
left ++;
}
if(left < right)
{
A[right --] = A[left];
}
}
A[left] = stand;
return left;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有