今天终于考完了,毫无压力。现在开始刷水题了,巩固下基础,嘿嘿。如果有更好的思路或方法可以留评论下来交流。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2020
直接代码水过:
#include<stdio.h> #include<math.h> #include<algorithm> using namespace std; bool comp(int x,int y) { return abs(x)>abs(y); } int main() { int n,i,a[101]; while(~scanf("%d",&n)&&n) { for(i=0;i<n;i++) { scanf("%d",&a[i]); } sort(a,a+n,comp); for(i=0;i<n;i++) { if(i==0) printf("%d",a[0]); else printf(" %d",a[i]); } printf("\n"); } return 0; }