九度 1007 奥运排序问题 (二)

2014-11-24 03:28:20 · 作者: · 浏览: 2
cmp4);
Ranks[3][0].iCountryId=RankCountrys[0].iCountryId;
Ranks[3][0].iRank=1;
for(i=1; i Ranks[3][i].iCountryId=RankCountrys[i].iCountryId;
if(RankCountrys[i].dPrizeRatio==RankCountrys[i-1].dPrizeRatio)
Ranks[3][i].iRank=Ranks[3][i-1].iRank;
else
Ranks[3][i].iRank=i+1;
}

//找出最佳排序方式输出 必须遍历每种排名中的每个元素 不然会漏掉
int rank,way;
bool first;
for(i=0; i first=true;
for(j=0; j<4; j++)
for(k=0; k if(Ranks[j][k].iCountryId==RankCountryId[i]) {
if(first) {
rank=Ranks[j][k].iRank;
way=j;
first=false;
} else {
if(Ranks[j][k].iRank rank=Ranks[j][k].iRank;
way=j;
}
}
}
}
printf("%d:%d\n",rank,way+1);
}
printf("\n");
}
return 0;
}
//按金牌数排序 降序

int cmp1(const void *a,const void *b)
{
Country *c1=(Country*)a;
Country *c2=(Country*)b;
return c2->dGold- c1->dGold;
}
//按奖牌数排序
int cmp2(const void *a,const void *b)
{
Country *c1=(Country*)a;
Country *c2=(Country*)b;
return c2->dPrize -c1->dPrize;
}
//按金牌人口比排序
int cmp3(const void *a,const void *b)
{
Country *c1=(Country*)a;
Country *c2=(Country*)b;
return c2->dGoldRatio > c1->dGoldRatio 1:-1;
}
//按奖牌人口比排序
int cmp4(const void *a,const void *b)
{
Country *c1=(Country*)a;
Country *c2=(Country*)b;
return c2->dPrizeRatio > c1->dPrizeRatio 1:-1;
}
/**************************************************************
Problem: 1007
User: windzhu
Language: C++
Result: Accepted
Time:10 ms
Memory:1108 kb
****************************************************************/