3 1 2 5 -1 5 3 1 2 3 4 5 0 0
5 5 4 3
#include <stdio.h> #include <stdlib.h> int compare(const void *p,const void *q){ return *(int *)q-*(int *)p; } int main() { int n,m; int a[100000]; int i; while(scanf("%d%d",&n,&m)!=EOF&&n!=0&&m!=0) { for(i=0;i<n;i++) scanf("%d",&a[i]); qsort(a,n,sizeof(int),compare); if(m>n){ for(i=0;i<n;i++) { if(i!=0) printf(" "); printf("%d",a[i]); } } else{ for(i=0;i<m;i++) { if(i!=0) printf(" "); printf("%d",a[i]); } } printf("\n"); } return 0; } /************************************************************** Problem: 1034 User: vhreal Language: C Result: Accepted Time:30 ms Memory:1240 kb ****************************************************************/
原文地址:http://blog.csdn.net/wtyvhreal/article/details/42342787