A. Gravity Flip time limit per test 1 second memory limit per test megabytes input standard input output standard OUTP Ut
Little Chris was bored during his physics lessons (too easy), so he had built a toy box to keep himself occupied. The box is special, since it had the ability to change gravity.
There is n columns of toy cubes in the box arranged in a line. The i-th column contains AI cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins-pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box:the cubes that has changed their position is highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the N columns after the Gravity switch! Input
The first line of input contains a integer n (1≤n≤100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number AI (1≤ai≤100) denotes the number of cubes in the i-th column. Output
Output n integer numbers separated by spaces, where the i-th number was the amount of cubes in the i-th column after the GR avity switch. Sample Test (s) input
4
3 2) 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case was shown on the figure. The top cube of the first column falls to the top of the last column; The top cube of the second column falls to the top of the third column; The middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does the heights of the columns.
Sort it out a bit.
/*******************************/
//by Pilgrim
/*******************************/
#include <string >
#include <cstring>
#include <cstdio>
#include <algorithm>
#include < iostream>
#include <cstdlib>
#include <vector>
using namespace std;
#define MAXN
A[MAXN];
int main ()
{
int n;
while (scanf ("%d", &n)!=eof)
{
memset (a,0,sizeof (a));
for (int i=0;i<n;i++)
scanf ("%d", &a[i]);
Sort (a,a+n);
for (int i=0;i<n;i++)
i==n-1?printf ("%d\n", A[i]):p rintf ("%d", A[i]);
}
return 0;
}