HDOJ2020 ( 绝对值排序 ) 【水题】


Problem : 2020 ( 绝对值排序 )     Judge Status : Accepted
RunId : 6000618    Language : C++    Author : qq1203456195
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <iostream>
 4 using namespace std;
 5 typedef struct Node
 6 {
 7     int data;
 8     int val;
 9 }NODE;
10 NODE node[101];
11 int cmp(NODE& a,NODE& b){    return a.val>b.val;}
12 int main()
13 {
14     int n,i;
15     while (scanf("%d",&n),n)
16     {
17         i=0;
18         while (i<n)
19         {
20             scanf("%d",&node[i].data);
21             node[i].val=abs(node[i].data);
22             i++;
23         }
24         sort(node,node+i,cmp);
25         printf("%d",node[0].data);
26         for (i=1;i<n;i++)
27             printf(" %d",node[i].data);
28         printf("\n");
29     }
30     return 0;
31 }

 

posted @ 2012-05-26 09:00  ZH奶酪  阅读(637)  评论(0编辑  收藏  举报