zoukankan      html  css  js  c++  java
  • 【ACM】hdu_2020_绝对值排序_201308050929

    绝对值排序
    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 30411    Accepted Submission(s): 15002


    Problem Description
    输入n(n<=100)个整数,按照绝对值从大到小排序后输出。题目保证对于每一个测试实例,所有的数的绝对值都不相等。
     

    Input
    输入数据有多组,每组占一行,每行的第一个数字为n,接着是n个整数,n=0表示输入数据的结束,不做处理。

    Output
    对于每个测试实例,输出排序后的结果,两个数之间用一个空格隔开。每个测试实例占一行。
     

    Sample Input
    3 3 -4 2
    4 0 1 2 -3
    0
     

    Sample Output
    -4 3 2
    -3 2 1 0
     

    Author
    lcy


    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>

    int cmp(const void *a,const void *b)
    {
     return abs(*(int *)b) - abs(*(int *)a);
    }//qsort排序
    int main()
    {
     int n;
     while(scanf("%d",&n),n)
     {
      int i,j=0;
      int a[110];
      for(i=0;i<n;i++)
      scanf("%d",&a[i]);
      qsort(a,n,sizeof(a[0]),cmp);
      for(i=0;i<n;i++)
      printf(j++?" %d":"%d",a[i]);
      printf(" ");
     }
     return 0;
    }

  • 相关阅读:
    Servlet CDI Example Analysis
    JSON续
    JSON
    Ubuntu 下安装 MySQL
    Filter介绍
    Annotation相关
    Container、Injection
    Java buildTools
    Http协议
    URI URL URN 的区别
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3237845.html
Copyright © 2011-2022 走看看