sicily 1154. Easy sort

Description

You know sorting is very important. And this easy problem is:

Given you an array with N non-negative integers which are smaller than 10,000,000, you have to sort this array. Sorting means that integer with smaller value presents first.

Input

The first line of the input is a positive integer T. T is the number of the test cases followed.

The first line of each test case is a positive integer N (1<= N<= 1000) which represents the number of integers in the array. After that, N lines followed. The i-th line is the i-th integer in the array.

Output
The output of each test case should consist of N lines. The i-th line is the i-th integer of the array after sorting. No redundant spaces are needed.
 
弱智版的排序题,连输出格式都不用特别注意,直接一堆换行……
如果不自己写排序,用库里自带的qsort函数,那就是神之水题了= =|||||||
一开始还以为要去重,就像弱智版的明明随机数,结果WA,才发现连去重都不要,只要排序再输出就行,果然水……
直接用了以前写的选择排序函数……简单问题复杂化,代码好长( ̄へ ̄)
 
View Code
 1 #include<stdio.h>
 2 #define MAX 1001
 3 
 4 void selectionSort( int array[], int size );
 5 void swapInArray( int array[], int first, int second );
 6 
 7 int main()
 8 {
 9     int array[MAX] = {0};
10     int t, n;
11     int i, j;
12     
13     scanf( "%d", &t );
14     
15     for ( i = 0; i < t; i++ )
16     {
17         scanf( "%d", &n );
18         
19         for ( j = 0; j < n; j++ )
20         {
21             scanf( "%d", &array[j] );
22         }
23         
24         selectionSort( array, n );
25         
26         for ( j = 0; j < n; j++ )
27         {
28             printf( "%d\n", array[j] );
29         }
30         
31     }
32     
33     return 0;
34 }
35 
36 void selectionSort( int array[], int size )
37 {
38     int i, j;
39     int min;
40     
41     for ( i = 0; i < size - 1; i++ )
42     {
43         min = i;
44         for ( j = i + 1 ; j < size; j++ )
45         {
46             if ( array[j] < array[min] )
47             {
48                 min = j;
49             }
50         }
51         
52         if ( i != min )
53         {
54             swapInArray( array, i, min );
55         }
56     }
57     
58     return;
59 }
60 
61 
62 void swapInArray( int array[], int first, int second )
63 {
64     int temp;
65     
66     temp = array[first];
67     array[first] = array[second];
68     array[second] = temp;
69     
70     return;
71 }

 

posted @ 2012-12-02 17:25  Joyee  阅读(339)  评论(0编辑  收藏  举报