CF A. Gravity Flip March 22

Source: Internet
Author: User
Tags integer numbers sort time limit

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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.