# UVa 11462 ### 題目連結:[UVa11462](http://domen111.github.io/UVa-Easy-Viewer/?11462) ### 題述: #### 給定一個國家所有人口的歲數資料(最少一歲,最多100歲),請由小到大排序歲數資料。 #### 有多組測試資料,每組資料一開始給定n(0<n<=2000000),表示人口總數。下一列會有n個整數表示每人的歲數。當n=0時表示輸入資料結束。 ### c++ code: ```cpp= #include<algorithm> #include<iostream> using namespace std; int main() { int n ; while( cin >> n ) { int age[n] ; if ( n == 0 ) { break ; } else { for ( int i = 0 ; i < n ; i++ ) { cin >> age[i] ; } sort(age,age+n) ; for ( int q = 0 ; q < n ; q++ ) { if ( q != 0 ) { cout << " " ; } cout << age[q] ; } cout << endl ; } } return 0; } ``` :::success **``sample input``** 5 3 4 2 1 5 5 2 3 2 3 1 0 ::: :::success **``sample output``** 1 2 3 4 5 1 2 2 3 3 ::: #### [返回首頁](https://hackmd.io/@fkleofk/APCS#11462) ###### tags: `APCS選修` `C++` `UVa`