HDU 3785- 寻找大富翁
2012-08-03 08:03
274 查看
/*algorithm 是算法的意思 #include <algorithm> 包括各种数据结构的具体元素检索、替换、逆序等等通用的算法 */ #include<iostream> #include<algorithm> using namespace std; bool cmp(int a,int b) { if(a>b) return true; //降序 else return false; } int main() { int m,n,i; int a[100000]; while(cin>>n>>m,n||m) { for(i=0;i<n;i++) cin>>a[i]; sort(a,a+n,cmp); //排序函数sort,对给定区间(a,a+n)所有元素进行排序 ,此处为降序 for(i=0;i<m;i++) { if(i==0) {cout<<a[i];continue;} cout<<' '<<a[i]; } cout<<endl; } return 0; }
#include<stdio.h> #include<stdlib.h> int cmp(const void *a,const void *b) { return *(int *)b-*(int *)a;//降序 } int main() { int m,n,i; int a[100000]; while(scanf("%d%d",&n,&m),n||m) { for(i=0;i<n;i++) scanf("%d",&a[i]); qsort(a,n,sizeof(a[0]),cmp); for(i=0;i<m;i++) { if(i==0) printf("%d",a[i]); else printf(" %d",a[i]); } putchar('\n'); } return 0; }
相关文章推荐
- HDU 3785 寻找大富翁 【栈】
- 【HDU 3785】寻找大富翁(sort或者优先队列-水题)
- HDU 3785 寻找大富翁 (排序)
- HDU 3785 寻找大富翁。
- G - 寻找大富翁 HDU 3785(对和比大小)
- HDU 3785 寻找大富翁
- HDU-#3785 寻找大富翁(优先队列)
- HDU 3785-寻找大富翁
- hdu杭电3785 寻找大富翁【优先队列】
- hdu——3785——寻找大富翁
- hdu_3785 寻找大富翁
- 【hdu 3785】寻找大富翁
- hdoj 3785 寻找大富翁
- hdoj 3785 寻找大富翁
- 【杭电】[3785]寻找大富翁
- HDU-寻找大富翁
- 杭电3785寻找大富翁
- hdu 3785 大富翁
- hdoj 3785 寻找大富翁(优先队列)
- 杭电3785寻找大富翁