本帖最后由 jhq999 于 2022-12-10 22:14 编辑 #include <stdio.h>
#include<stdlib.h>
int cmp(void* a,void *b)
{
int *a1=(int*)a;
int *b1=(int*)b;
if(a1[0]>b1[0])return 1;
else if(a1[0]<b1[0])return -1;
else if(a1[1]>b1[1]) return 1;
else if(a1[1]<b1[1]) return -1;
return 0;
}
int cmp1(void* a,void *b)
{
return *(int*)a-*(int*)b;
}
int main()
{
int n;
scanf("%d",&n);
if(n<5)return 0;
int a[n][2],*a1=(int*)a;
long long *a2=(long long*)a;
for(int i=0;i<2*n;i+=1 )scanf("%d",a1+i);
/*qsort(a1,2*n,sizeof(int),cmp1);
for(int i=0;i<2*n;i+=1)printf("%d ",a1[i]);*/
qsort(a2,n,sizeof(long long ),cmp);
for(int i=0;i<2*n;i+=1)printf("%d ",a1[i]);
return 0;
忘了写输出优先级为2的数,相信楼主直接会写5
2 1 0 9 5 7 8 3 4 6
0 9 2 1 4 6 5 7 8 3
Process returned 0 (0x0) execution time : 9.234 s
Press any key to continue.
|