游客 Signup | Login
中文 | En

2558 - 计数排序

输入n个整数(n<=5000),从小到大输出。(使用计数排序)

Input

Output

Examples

Input


                

Output


                

Solution C++

#include<bits/stdc++.h>
using namespace std;
#define M 100005
int A[M],cnt[M],B[M];
int main(){
      int n,x;
      cin>>n;
	   
      for(int i=1;i<=n;i++){
      	cin>>A[i]; 
      	cnt[A[i]]++;
	  } 
	  for(int i=1;i<=M;i++)cnt[i]=cnt[i]+cnt[i-1];
	  for(int i=n;i>=1;i--)B[cnt[A[i]]--]=A[i];
	  
	  for(int i=1;i<=n;i++) printf("%d ",B[i]); 
      return 0;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题