Server Time: Fri Jul 19, 2019 6:32 am
 Welcome ( logout )
1091 - The Fastest Sorting Ever!
 PDF (English) Statistics Forum
 Time Limit: 2 second(s) Memory Limit: 32 MB

Sorting algorithms are essentially necessary in computer science. If there are n numbers then the best time to sort the numbers is O(n log n). Here you are asked to write a code that will sort the numbers in ascending order using only 'if' and 'else' statements.

In your code, you should attach the function to print (as in sample) the numbers. In your codes you can use spaces freely, but be careful to use spaces in the printing format (as in the sample printf). It should be exact. And no lines should be empty.

# Constraints

1.      Your code should contain a function named print() which prints the variables. You can use spaces freely but the format in printf should be correct. There should be n parameters for print() and they are a, b, c, ... (ascending order). The printf (as in C) should print all of them in ascending order. First three lines should be the print function. See the samples.

2.      Your code should contain a function named sort().The parameters should be same as print(). It should contain three kinds of statements

a.      if( x < y )

b.      else

c.      print( a, b, ... );

3.      Every statement should be in a single line. And no line should be empty.

4.      Nested if statements are allowed. And every if statement should have a corresponding else statement.

5.      Assume that the inputs given to your code will be distinct. That means for any two given inputs x, y you can assume that x ≠ y.

6.      For a code for n variables there should be exactly n! * 3 +3 lines (excluding the case).

7.      Check the samples very carefully for other clarifications.

# Input

Input starts with an integer T (≤ 7), denoting the number of test cases.

Each case contains an integer n (1 ≤ n ≤ 7) denoting the numbers that will be given as input to your code.

# Output

For each case, print the case number in a line. Then you have to print your code. Check the samples for the formatting details. There can be multiple solutions, print any valid solution.

# Output for Sample Input

3

1

2

3

Case 1:

void print( int a ) {

printf( "%d\n", a );

}

void sort( int a ) {

print( a );

}

Case 2:

void print(int a,int b){

printf( "%d %d\n",a,b);

}

void sort( int a, int b){

if( b < a )

print( b, a );

else

print( a, b );

}

Case 3:

void print( int a, int b, int c ) {

printf( "%d %d %d\n", a, b, c );

}

void sort( int a, int b, int c ) {

if( a < b )

if( a < c )

if( b < c )

print( a, b, c );

else

print( a, c, b );

else

print( c, a, b );

else

if( b < c )

if( a < c )

print( b, a, c );

else

print( b, c, a );

else

print( c, b, a );

}

Problem Setter: Jane Alam Jan
Special Thanks: Samir Ahmed
 Developed and Maintained by JANE ALAM JAN Copyright © 2012 LightOJ, Jane Alam Jan