?? sort.h
字號(hào):
#include "data.h"
#include "string.h"
#include "Print.h"
//3. 成績(jī)總體排名。
//a) 按國(guó)家名字排名(如:America應(yīng)排在Russia前面)
//b) 按國(guó)家所屬大洲排名,同大洲內(nèi)國(guó)家依照a)的排名規(guī)則
//c) 按國(guó)家獲得的成績(jī)排名(兩種排名規(guī)則,按金牌數(shù)和分?jǐn)?shù)成績(jī)排名)
void Sort_Country();/*按照國(guó)家的名字排序*/
void Sort_Continent();/*按照所屬于的大洲排序*/
void Sort_Item();/*按照運(yùn)動(dòng)成績(jī)*/
void Sort_Goldplate();/*按照金牌排序*/
void Sort_Integral();/*按照積分排序*/
void Sort()
{
int chose=0;
printf ("\t\t\t1.按國(guó)家的紀(jì)錄排序\n");
printf ("\t\t\t2.按洲的記錄排序\n");
printf ("\t\t\t3.按成績(jī)排序\n");
printf ("\t\t\t4.請(qǐng)退出系統(tǒng) \n");
do{
printf ("\n\t\t\tEnter your choice(1~4):");
/*fflush(stdin);*/scanf("%d",&chose);
switch(chose)
{
case 1:
Sort_Country();/*函數(shù)---根據(jù)國(guó)家的名字排序*/
break;
case 2:
Sort_Continent();/*函數(shù)--根據(jù)每個(gè)國(guó)家所屬于的大洲名字排序*/
break;
case 3:
Sort_Item();/*根據(jù)運(yùn)動(dòng)成績(jī)排序*/
break;
case 4:
exit(0);
break;/*退出此次操作*/
}
}while(chose<1||chose>4);
}
/*按照國(guó)家的名字排序*/
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)/*比較國(guó)家的名稱(chēng)來(lái)比較排序*/
{
/*下面是進(jìn)行相應(yīng)的排序*/
struct Olympic temp;
temp=Country[i];
Country[i]=Country[j];
Country[j]=temp;
}
}
}
Print_Country();/*排序好后,調(diào)用此函數(shù)輸出相應(yīng)的排序信息*/
}
/*按照所屬于的大洲排序*/
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)/*根據(jù)國(guó)家所屬于的大洲名稱(chēng)來(lái)比較排序*/
{
/*下面是進(jìn)行相應(yīng)的排序*/
struct Olympic temp;
temp=Country[j-1];
Country[j-1]=Country[j];
Country[j]=temp;
}
}
}
Print_Continent();/*排序好,調(diào)用此函數(shù)輸出相應(yīng)的排序信息*/
}
/*按照運(yùn)動(dòng)成績(jī)*/
void Sort_Item()
{
int chose;
printf ("\t\t\t1.排序的紀(jì)錄\n");
printf ("\t\t\t2.按積分排序的紀(jì)錄積分\n");
printf ("\t\t\t3.請(qǐng)退出程序\n");
do{
printf("\n\t\t\tEnter your choice(1~3):");
scanf("%d",&chose);
switch(chose)
{
case 1:
Sort_Goldplate();/*此函數(shù)--是根據(jù)金牌的數(shù)量排序*/
break;
case 2:
Sort_Integral();/*此函數(shù)--是根據(jù)國(guó)家的積分排序*/
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)/*根據(jù)每個(gè)國(guó)家的金牌數(shù)量比較排序*/
{
/*下面進(jìn)行相應(yīng)的排序*/
struct Olympic temp;
temp=Country[j-1];
Country[j-1]=Country[j];
Country[j]=temp;
}
}
}
Print_Goldplate();/*排序好,調(diào)用此函數(shù)輸出相應(yīng)的排序信息*/
}
/*按照積分排序*/
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)/*根據(jù)每個(gè)國(guó)家的積分排序*/
{
/*下面是進(jìn)行相應(yīng)的排序*/
struct Olympic temp;
temp=Country[j-1];
Country[j-1]=Country[j];
Country[j]=temp;
}
}
}
Print_Integral();/*排序好后,調(diào)用此函數(shù)輸出相應(yīng)的排序信息*/
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -