不忘初心,砥砺前行!
1030: Age Sort
Time Limit: 1 Sec Memory Limit: 2 MBSubmit: 2423 Solved: 608
[ Submit][ Status][ Web Board]
Description
You are given the ages (in years) of allpeople of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very simple task of sorting all the ages in ascending order.
Input
There are multiple test cases in the input file. Each case starts with an integer n (0<n<=1000000), the total number of people. In the next line, there are n integers indicating the ages. Input is terminated with a case where n = 0. This case should not be processed.
Output
For each case, print a line with n space separated integers. These integers are the ages of that country sorted in ascending order.
Sample Input
53 4 2 1 552 3 2 3 10
Sample Output
1 2 3 4 51 2 2 3 3
HINT
Source
#include<cstdio> #include<string.h> #include<iostream> #include<algorithm> using namespace std; int a[105]; int main() { int n,m,flag; while(~scanf("%d",&n)&&n!=0) { memset(a,0,sizeof(a)); for(int i=1;i<=n;i++){ scanf("%d",&m); a[m]++; } flag=0; for(int i=1;i<=100;i++){ for(int j=1;j<=a[i];j++){ if(flag==0) {printf("%d",i);flag=1;} else printf(" %d",i); } } printf("\n"); } return 0; }