📄 sort.h
字号:
#include "data.h"
#include "string.h"
#include "Print.h"
//3. 成绩总体排名。
//a) 按国家名字排名(如:America应排在Russia前面)
//b) 按国家所属大洲排名,同大洲内国家依照a)的排名规则
//c) 按国家获得的成绩排名(两种排名规则,按金牌数和分数成绩排名)
void Sort_Country();/*按照国家的名字排序*/
void Sort_Continent();/*按照所属于的大洲排序*/
void Sort_Item();/*按照运动成绩*/
void Sort_Goldplate();/*按照金牌排序*/
void Sort_Integral();/*按照积分排序*/
void Sort()
{
int chose=0;
printf ("\t\t\t1.按国家的纪录排序\n");
printf ("\t\t\t2.按洲的记录排序\n");
printf ("\t\t\t3.按成绩排序\n");
printf ("\t\t\t4.请退出系统 \n");
do{
printf ("\n\t\t\tEnter your choice(1~4):");
/*fflush(stdin);*/scanf("%d",&chose);
switch(chose)
{
case 1:
Sort_Country();/*函数---根据国家的名字排序*/
break;
case 2:
Sort_Continent();/*函数--根据每个国家所属于的大洲名字排序*/
break;
case 3:
Sort_Item();/*根据运动成绩排序*/
break;
case 4:
exit(0);
break;/*退出此次操作*/
}
}while(chose<1||chose>4);
}
/*按照国家的名字排序*/
void Sort_Country()
{
int i,j;
for(i=0;i<N;i++)
{
for(j=i+1;j<N-i;j++)
{
if(strcmp(Country[i].GName,Country[j].GName)>0)/*比较国家的名称来比较排序*/
{
/*下面是进行相应的排序*/
struct Olympic temp;
temp=Country[i];
Country[i]=Country[j];
Country[j]=temp;
}
}
}
Print_Country();/*排序好后,调用此函数输出相应的排序信息*/
}
/*按照所属于的大洲排序*/
void Sort_Continent()
{
int i,j;
for(i=0;i<N;i++)
{
for(j=1;j<N-i;j++)
{
if(strcmp(Country[j-1].GContinent,Country[j].GContinent)>0)/*根据国家所属于的大洲名称来比较排序*/
{
/*下面是进行相应的排序*/
struct Olympic temp;
temp=Country[j-1];
Country[j-1]=Country[j];
Country[j]=temp;
}
}
}
Print_Continent();/*排序好,调用此函数输出相应的排序信息*/
}
/*按照运动成绩*/
void Sort_Item()
{
int chose;
printf ("\t\t\t1.排序的纪录\n");
printf ("\t\t\t2.按积分排序的纪录积分\n");
printf ("\t\t\t3.请退出程序\n");
do{
printf("\n\t\t\tEnter your choice(1~3):");
scanf("%d",&chose);
switch(chose)
{
case 1:
Sort_Goldplate();/*此函数--是根据金牌的数量排序*/
break;
case 2:
Sort_Integral();/*此函数--是根据国家的积分排序*/
break;
case 3:
exit(0);
break;/*退出此次操作*/
}
}while(chose<1||chose>3);
}
/*按照金牌排序*/
void Sort_Goldplate()
{
int i,j;
for(i=0;i<N;i++)
{
for(j=1;j<N-i;j++)
{
if(Country[j-1].Goldplate<Country[j].Goldplate)/*根据每个国家的金牌数量比较排序*/
{
/*下面进行相应的排序*/
struct Olympic temp;
temp=Country[j-1];
Country[j-1]=Country[j];
Country[j]=temp;
}
}
}
Print_Goldplate();/*排序好,调用此函数输出相应的排序信息*/
}
/*按照积分排序*/
void Sort_Integral()
{
int i,j;
for(i=0;i<N;i++)
{
for(j=1;j<N-i;j++)
{
if(Country[j-1].Integral<Country[j].Integral)/*根据每个国家的积分排序*/
{
/*下面是进行相应的排序*/
struct Olympic temp;
temp=Country[j-1];
Country[j-1]=Country[j];
Country[j]=temp;
}
}
}
Print_Integral();/*排序好后,调用此函数输出相应的排序信息*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -