写好了且测试数据过了,问题在于j++上,要先算再+
#include <stdio.h>
#include <stdlib.h>
void merge(int first,int last,int mid,int number[],int score[])
{
int score_temp[10]={0},number_temp[10]={0};
int i=first,j=mid+1,k;
for(k=0;k<=last-first;k++)
{
if(i==mid+1)
{
score_temp[k]=score[j];
number_temp[k]=number[j];
j++;
continue;
}
if(j==last+1)
{
score_temp[k]=score[i];
number_temp[k]=number[i];
i++;
continue;
}
if(score[i]<score[j])
score_temp[k]=score[i],number_temp[k]=number[i],i++;
else if(score[i]==score[j]&&number[i]>number[j])
score_temp[k]=score[i],number_temp[k]=number[i],i++;
else
score_temp[k]=score[j],number_temp[k]=number[j],j++;
}
j=0;
for(k=first;k<=last;k++,j++)
{
score[k]=score_temp[j];
number[k]=number_temp[j];
}
}
void merge_sort(int first,int last,int number[],int score[])
{
int mid=0;
if(first<last)
{
mid=(first+last)/2;
merge_sort(first,mid,number,score);
merge_sort(mid+1,last,number,score);
merge(first,last,mid,number,score);
}
}
int main()
{
int number[10]={0},score[10]={0},i,n;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d %d",&number[i],&score[i]);
merge_sort(0,n-1,number,score);
printf("\n");
for(i=0;i<n;i++)
printf("%d %d\n",number[i],score[i]);
system("pause");
return 0;
}