程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Round #238 (Div. 2) A題

Codeforces Round #238 (Div. 2) A題

編輯:C++入門知識

A. Gravity Flip time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

大水題,直接排序輸出

Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.

There are 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 to 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 have changed their position are 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!<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KCgoKSW5wdXQKPHA+ClRoZSBmaXJzdCBsaW5lIG9mIGlucHV0IGNvbnRhaW5zIGFuIGludGVnZXIgPGVtPm48L2VtPiAoMT+h3D88ZW0+bjwvZW0+P6HcPzEwMCksCiB0aGUgbnVtYmVyIG9mIHRoZSBjb2x1bW5zIGluIHRoZSBib3guIFRoZSBuZXh0IGxpbmUgY29udGFpbnMgPGVtPm48L2VtPiBzcGFjZS1zZXBhcmF0ZWQgaW50ZWdlciBudW1iZXJzLiBUaGUgPGVtPmk8L2VtPi10aAogbnVtYmVyIDxlbT5hPC9lbT48ZW0+aTwvZW0+ICgxP6HcPzxlbT5hPC9lbT48ZW0+aTwvZW0+P6HcPzEwMCkKIGRlbm90ZXMgdGhlIG51bWJlciBvZiBjdWJlcyBpbiB0aGUgPGVtPmk8L2VtPi10aCBjb2x1bW4uPC9wPgoKCgpPdXRwdXQKPHA+Ck91dHB1dCA8ZW0+bjwvZW0+IGludGVnZXIgbnVtYmVycyBzZXBhcmF0ZWQgYnkgc3BhY2VzLCB3aGVyZSB0aGUgPGVtPmk8L2VtPi10aAogbnVtYmVyIGlzIHRoZSBhbW91bnQgb2YgY3ViZXMgaW4gdGhlIDxlbT5pPC9lbT4tdGggY29sdW1uIGFmdGVyIHRoZSBncmF2aXR5IHN3aXRjaC48L3A+CgoKClNhbXBsZSB0ZXN0KHMpCgoKCmlucHV0CjxwcmUgY2xhc3M9"brush:java;">4 3 2 1 2 output

1 2 2 3 
input
3
2 3 8
output
2 3 8 
Note

The first example case is 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 not change the heights of the columns.

#include
#include
#include
#define max 101
int n;int cloum[max];
int main()
{
    //freopen("input.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)scanf("%d",&cloum[i]);
        std::sort(cloum+1,cloum+n+1);
        for(int i=1;i<=n;i++)
        printf("%d%c",cloum[i],i==n?'\n':' ');
    }
    return 0;
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved