题解 | #奥运排序问题#
奥运排序问题
https://www.nowcoder.com/practice/100a4376cafc439b86f5f8791fb461f3
本题需要5个排序 分别对金牌 奖牌 金牌人口比例 奖牌人口比例。 同时还要保证与输入时的顺序相同 所以要在结构体中定义顺序 并在输入时对顺序赋值。 还有对每一次排序之后排名的确定 需要对chazhi变量清0来保证排名的正确 我个人感觉这点很容易被忽视。 以下是代码: #include<stdio.h> #include<math.h> #include<string.h> struct medal { int gold; int medal; float population; float gold_scale; float medal_scale; int tag;//用于记录最小排名方式 int paiming[4]; int shunxu; }medal[100000]; int main() { int n,m,i,min; int chazhi; int paiming; void quicksort1(struct medal medal[],int low,int high);//生命4种排序方式 每次排序都确定一种排序的 void quicksort2(struct medal medal[],int low,int high);//最终位置 同时寻找最高排名 void quicksort3(struct medal medal[],int low,int high);// void quicksort4(struct medal medal[],int low,int high);// void quicksort5(struct medal medal[],int low,int high); while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<n;i++)//输入金牌数 奖牌数 人口 并计算对应的比例 并且加上标记来为每次排序后找前后 { scanf("%d %d %f",&medal[i].gold,&medal[i].medal,&medal[i].population); medal[i].gold_scale=medal[i].gold/medal[i].population; medal[i].medal_scale=medal[i].medal/medal[i].population; medal[i].tag=i; medal[i].shunxu=i; for(int j=0;j<4;j++) medal[i].paiming[j]=0;//重置排名 } quicksort1(medal,0,n-1);//排序完之后开始记录按这种方式的排名 { chazhi=0;paiming=1; medal[0].paiming[0]=paiming; for(i=1;i<n;i++) { if(medal[i].gold==medal[i-1].gold)//前后相同时 排名相同 { medal[i].paiming[0]=medal[i-1].paiming[0]; chazhi++; } else { paiming=paiming+chazhi+1; medal[i].paiming[0]=paiming; chazhi=0; } } } quicksort2(medal,0,n-1); { chazhi=0;paiming=1; medal[0].paiming[1]=paiming; for(i=1;i<n;i++) { if(medal[i].medal==medal[i-1].medal)//前后相同时 排名相同 { medal[i].paiming[1]=medal[i-1].paiming[1]; chazhi++; } else { paiming=paiming+chazhi+1; medal[i].paiming[1]=paiming; chazhi=0; } } } quicksort3(medal,0,n-1); { chazhi=0;paiming=1; medal[0].paiming[2]=paiming; for(i=1;i<n;i++) { if(medal[i].gold_scale==medal[i-1].gold_scale)//前后相同时 排名相同 { medal[i].paiming[2]=medal[i-1].paiming[2]; chazhi++; } else { paiming=paiming+chazhi+1; medal[i].paiming[2]=paiming; chazhi=0; } } } quicksort4(medal,0,n-1); { chazhi=0;paiming=1; medal[0].paiming[3]=paiming; for(i=1;i<n;i++) { if(medal[i].medal_scale==medal[i-1].medal_scale)//前后相同时 排名相同 { medal[i].paiming[3]=medal[i-1].paiming[3]; chazhi++; } else { paiming=paiming+chazhi+1; medal[i].paiming[3]=paiming; chazhi=0; } } } for(i=0;i<n;i++) { min=9999; for(int j=0;j<4;j++) { if(medal[i].paiming[j]<min) { medal[i].tag=j; min=medal[i].paiming[j]; } } } quicksort5(medal,0,n-1);//最后按照输入顺序进行排序 for(i=0;i<m;i++) { int num; scanf("%d",&num); printf("%d:%d\n",medal[num].paiming[medal[num].tag],medal[num].tag+1); } printf("\n"); } return 0; } void quicksort1(struct medal medal[],int low,int high) { int position1(struct medal medal[],int low,int high); if(low<high) { int axis=position1(medal,low,high); quicksort1(medal,low,axis-1); quicksort1(medal,axis+1,high); } } int position1(struct medal medal[],int low,int high)//第一种排序 按照金牌总数从大到小排序 { float temp; while(low<high)//交替排序 先右再左 { while(low<high) { if(medal[low].gold<medal[high].gold) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 //交换排名 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } break; } else if(medal[low].gold==medal[high].gold)//相等时按排名排序 { if(medal[low].tag>medal[high].tag) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 //交换排名 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } } } high--; } while(low<high) { if(medal[low].gold<medal[high].gold) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } break; } else if(medal[low].gold==medal[high].gold)//相等时按排名排序 { if(medal[low].tag>medal[high].tag) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 //交换排名 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } } } low++; } } return low; } void quicksort2(struct medal medal[],int low,int high)//按照奖牌总数排序 { int position2(struct medal medal[],int low,int high); if(low<high) { int axis=position2(medal,low,high); quicksort2(medal,low,axis-1); quicksort2(medal,axis+1,high); } } int position2(struct medal medal[],int low,int high)//第二种排序 按照奖牌总数从大到小排序 { float temp; while(low<high)//交替排序 先右再左 { while(low<high) { if(medal[low].medal<medal[high].medal) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } break; } else if(medal[low].medal==medal[high].medal)//相等时按排名排序 { if(medal[low].tag>medal[high].tag) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 //交换排名 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } } } high--; } while(low<high) { if(medal[low].medal<medal[high].medal) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } break; } else if(medal[low].medal==medal[high].medal)//相等时按排名排序 { if(medal[low].tag>medal[high].tag) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 //交换排名 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } } } low++; } } return low; } void quicksort3(struct medal medal[],int low,int high)//按照金牌人口比例排序 { int position3(struct medal medal[],int low,int high); if(low<high) { int axis=position3(medal,low,high); quicksort3(medal,low,axis-1); quicksort3(medal,axis+1,high); } } int position3(struct medal medal[],int low,int high)//第三种排序 按照金牌人口比例从大到小排序 { float temp; while(low<high)//交替排序 先右再左 { while(low<high) { if(medal[low].gold_scale<medal[high].gold_scale) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } break; } else if(medal[low].gold_scale==medal[high].gold_scale)//相等时按排名排序 { if(medal[low].tag>medal[high].tag) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 //交换排名 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } } } high--; } while(low<high) { if(medal[low].gold_scale<medal[high].gold_scale) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } break; } else if(medal[low].gold_scale==medal[high].gold_scale)//相等时按排名排序 { if(medal[low].tag>medal[high].tag) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 //交换排名 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } } } low++; } } return low; } void quicksort4(struct medal medal[],int low,int high)//按照奖牌人口比例排序 { int position4(struct medal medal[],int low,int high); if(low<high) { int axis=position4(medal,low,high); quicksort4(medal,low,axis-1); quicksort4(medal,axis+1,high); } } int position4(struct medal medal[],int low,int high)//第四种排序 按照金牌人口比例从大到小排序 { float temp; while(low<high)//交替排序 先右再左 { while(low<high) { if(medal[low].medal_scale<medal[high].medal_scale) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } break; } else if(medal[low].medal_scale==medal[high].medal_scale)//相等时按排名排序 { if(medal[low].tag>medal[high].tag) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 //交换排名 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } } } high--; } while(low<high) { if(medal[low].medal_scale<medal[high].medal_scale) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } break; } else if(medal[low].medal_scale==medal[high].medal_scale)//相等时按排名排序 { if(medal[low].tag>medal[high].tag) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 //交换排名 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i];; medal[low].paiming[i]=temp; } } } low++; } } return low; } void quicksort5(struct medal medal[],int low,int high) { int position5(struct medal medal[],int low,int high); if(low<high) { int axis=position5(medal,low,high); quicksort5(medal,low,axis-1); quicksort5(medal,axis+1,high); } } int position5(struct medal medal[],int low,int high)//第一种排序 按照金牌总数从大到小排序 { float temp; while(low<high)//交替排序 先右再左 { while(low<high) { if(medal[low].shunxu>medal[high].shunxu) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 //交换排名 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i]; medal[low].paiming[i]=temp; } break; } high--; } while(low<high) { if(medal[low].shunxu>medal[high].shunxu) { temp=medal[high].gold; medal[high].gold=medal[low].gold; medal[low].gold=temp;//交换金牌 temp=medal[high].medal; medal[high].medal=medal[low].medal; medal[low].medal=temp;//交换奖牌 temp=medal[high].population; medal[high].population=medal[low].population; medal[low].population=temp;//交换人口 temp=medal[high].gold_scale; medal[high].gold_scale=medal[low].gold_scale; medal[low].gold_scale=temp;//交换金牌人口比例 temp=medal[high].medal_scale; medal[high].medal_scale=medal[low].medal_scale; medal[low].medal_scale=temp;//交换奖牌人口比例 temp=medal[high].tag; medal[high].tag=medal[low].tag; medal[low].tag=temp;//交换标记 temp=medal[high].shunxu; medal[high].shunxu=medal[low].shunxu; medal[low].shunxu=temp;//交换标记 for(int i=0;i<4;i++) { temp=medal[high].paiming[i]; medal[high].paiming[i]=medal[low].paiming[i]; medal[low].paiming[i]=temp; } break; } low++; } } return low; }