绝对值排序
1 #include2 #include 3 #include 4 #include<string.h> 5 int main() 6 { 7 int n; 8 int a[1000]; 9 int b[1000]; 10 int i; 11 int t,j; 12 while (1) 13 { 14 scanf("%d",&n); 15 if (!n) break; 16 for (i=1;i<=n;i++) 17 { 18 scanf("%d",&a[i]); 19 b[i]=abs(a[i]); 20 } 21 for (i=1;i ) 22 for (j=i;j<=n;j++) 23 { 24 if (b[i]<b[j]) 25 { 26 t=a[i]; 27 a[i]=a[j]; 28 a[j]=t; 29 t=b[i]; 30 b[i]=b[j]; 31 b[j]=t; 32 } 33 } 34 for (i=1;i "%d ",a[i]); 35 printf("%d ",a[i]); 36 } 37 return 0; 38 }