zoukankan      html  css  js  c++  java
  • HDU 1040 As Easy As A+B

    Problem Description
    These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.
    Give you some integers, your task is to sort these number ascending (升序).
    You should know how easy the problem is now!
    Good luck!
     

    Input

    Input contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in the same line.
    It is guarantied that all integers are in the range of 32-int.

     

     

    Output
    For each case, print the sorting result, and one line one case.
     

     

    Sample Input
    2 3 2 1 3 9 1 4 7 2 5 8 3 6 9
     

     

    Sample Output
    1 2 3 1 2 3 4 5 6 7 8 9
     
    题意:输入一个数T限制输入T行,每行开头输入一个整数N,表示此行输入N个数,对这N个数进行排序。
    分析:用一维数组存放输入的N个整数,用两个for循环对这N个数排序。
    AC源代码(C语言):
     1 #include<stdio.h>
     2 int main()
     3 {
     4   int m,n,i,j,t,s[1000];
     5   scanf("%d",&n);
     6   while(n--)
     7   {
     8     scanf("%d",&m);        
     9     for(i=0;i<m;i++)
    10       {
    11          scanf("%d",&s[i]);           
    12       }          
    13     for(i=0;i<m;i++)
    14      for(j=i;j<m;j++)
    15       {
    16         if(s[i]>s[j])
    17           {
    18            t=s[i];
    19            s[i]=s[j];
    20            s[j]=t;          
    21           }           
    22       }         
    23     for(i=0;i<m-1;i++)
    24       printf("%d ",s[i]);
    25     printf("%d\n",s[i]);        
    26   }
    27   return 028 }

    2013-01-13

  • 相关阅读:
    Js获取或计算时间的相关操作
    SqlServer删除表中重复的记录并保留一条
    获取js文件后的参数
    谷歌浏览器官方下载地址
    ionic项目中实现发短信和打电话
    ui-router传递参数
    ng-options用法详解
    html5 localStorage(本地存储)
    cordova插件之Local Notification(本地通知)
    AngularJS $http service
  • 原文地址:https://www.cnblogs.com/fjutacm/p/2858788.html
Copyright © 2011-2022 走看看