您的位置:首页 > 其它

绝对值排序解题报告

2013-02-22 14:26 197 查看
原题:点击题目链接

分析:水题一枚,不解释;

水神一个,难题不会~

源码:

#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct N
{
    int a;
    int b;
}p[101];
int cmp(N g,N h)
{
    return g.b>h.b;
}
int main()
{
    int n;
    while(scanf("%d",&n)&&(n!=0))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&p[i].a);
        }
        for(int j=0;j<n;j++)
        {
            p[j].b=fabs(p[j].a);
        }
        sort(p,p+n,cmp);
        for(int f=0;f<n-1;f++)
        {
            printf("%d ",p[f].a);
        }
        printf("%d\n",p[n-1].a);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: