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

  • 相关阅读:
    四组API
    常用的辅助类(必会
    时间戳
    SpringMVC JSON乱码解决
    数据显示到前端
    ubuntu vim字体高亮
    vi编辑文件保存后,提示""vimrc" E212: Can't open file for writing Press ENTER or type command to continu"
    C语言程序设计100例之(25):确定进制
    C语言程序设计100例之(24):数制转换
    C语言程序设计100例之(23):数列求和
  • 原文地址:https://www.cnblogs.com/fjutacm/p/2858788.html
Copyright © 2011-2022 走看看