绝对值排序
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int cmp(const void *a,const void *b) { return abs(*(int *)a)< abs(*(int *)b)?1:-1; } int main( ) { int N,A[10000]; while(scanf("%d",&N),N) { int i,j,k; for(i=0;i<N;i++) scanf("%d",&A[i]); qsort(A,N,sizeof(A[0]),cmp); for(i=0;i<N;i++) printf(i?" %d":"%d",A[i]); puts(""); } return 0; }
posted on 2011-04-28 16:58 more think, more gains 阅读(180) 评论(0) 编辑 收藏 举报