注意qsort的cmp函数为int,大数不能直接return
include
include
long long abs(long long k){
if(k<0){
k=-k;
}
return k;
}
typedef struct{
long long num;
long long numabs;
long long c;
}sort;
int cmp(const void x,const void y){
sort a=(sort )x;
sort b=(sort )y;
if(a->c==b->c){
return a->num>b->num? 1:-1 ;
}
return b->c-a->c;
}
int main(){
int t,d=0;
scanf(“%d”,&t);
while(t>0){
int n,i;
scanf(“%d”,&n);
sort k[10000];
for(i=0;i<n;i++){
scanf(“%lld”,&k[i].num);
k[i].numabs=abs(k[i].num);
long long p=k[i].numabs;
while(1){
if(p<10){
k[i].c=p;
break;
}
p=p/10;
}
}
qsort(k,n,sizeof(k[0]),cmp);
printf(“case #%d:\n%lld”,d,k[0].num);
for(i=1;i<n;i++){
printf(" %lld",k[i].num);
}
printf("\n");
t--;d++;
}
}
厉害了我的昊宇!