sort
Description
Input
Output
Sample Input
Sample Output
Hint
Hint 请用VC/VC++提交
#include<stdio.h> int s[1000000]; int adjust(int s[], int l, int r) { int i = l, j = r; int x = s[l]; while(i < j){ while(i < j && s[j] >= x ) j--; if(i < j) { s[i] = s[j]; i++; } while(i < j && s[i] < x ) i++; if(i < j){ s[j] = s[i]; j--; } } s[i] = x; return i; } void qsort(int s[], int l, int r) { if(l < r){ int i = adjust(s, l, r); qsort(s, l, i-1); qsort(s, i+1, r); } } int main(){ int n, m; while(~scanf("%d%d", &n, &m)){ for(int i=0; i<n; i++) scanf("%d", &s[i]); qsort(s, 0, n-1); for(int i=n-1; i>=n-m; i--) i==n-1? printf("%d", s[i]) : printf(" %d", s[i]); printf("\n"); } return 0; }