今天终于考完了,毫无压力
。现在开始刷水题了,巩固下基础,嘿嘿。如果有更好的思路或方法可以留评论下来交流。
题目链接: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; }
本文分享了一道来自HDU在线评测系统的简单编程题的解题思路及代码实现。通过使用C++语言并结合标准库函数sort进行排序,实现了对输入整数按绝对值从大到小的排序输出。
321

被折叠的 条评论
为什么被折叠?



