#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef double dl; #define endl "\n" #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); int main() { int n; cin>>n; int arr[n];int b[n]; int max=0; for(int i=0;i<n;i++){ cin>>arr[i]; if(arr[i]>max)max=arr[i]; } int count_arr[max+1]; for(int i=0;i<=max;i++){ count_arr[i]=0; } for(int i=0;i<n;i++){ count_arr[arr[i]]++; } for(int i=1;i<=max;i++){ count_arr[i]=count_arr[i]+count_arr[i-1]; } for(int i=n-1;i>=0;i--){ b[--count_arr[arr[i]]]=arr[i]; } for(int i=0;i<n;i++){ cout<<b[i]<<" "; } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter