标签:style blog http color for io
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2020
题目大意:按照绝对值大小从大到小排序,注意输出两个数之间要用空格隔开,在这里引入一个冒泡排序,两个循环即可!
1 #include <stdio.h> 2 #include <math.h> 3 int main () 4 { 5 int n,a[100],i,j,t; 6 while (scanf("%d",&n),n) 7 { 8 for (i=0; i<n; i++) 9 scanf(" %d",&a[i]); 10 for (i=0; i<n; i++) 11 { 12 for (j=i; j<n; j++) 13 { 14 if (fabs(a[j])>fabs(a[i])) 15 { 16 t=a[i]; 17 a[i]=a[j]; 18 a[j]=t; 19 } 20 } 21 if (i>0) printf (" "); 22 printf ("%d",a[i]); 23 } 24 printf ("\n"); 25 } 26 return 0; 27 }
标签:style blog http color for io
原文地址:http://www.cnblogs.com/qq-star/p/3840904.html