码迷,mamicode.com
首页 > 其他好文 > 详细

小希的数表2(用的for循环)

时间:2016-12-16 17:03:18      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:for   algorithm   pre   for循环   cout   return   nbsp   cin   sort   

#include<iostream>  
02.#include<algorithm>  
03.using namespace std;  
04.  
05.bool cmp(int a,int b){  
06.    return a>b;  
07.}  
08.  
09.int p[9000010],n,k;  
10.int a[3005];  
11.  
12.int main(){  
13.    while(cin>>n>>k){  
14.        for( int i = 0 ; i < n ; ++i )  
15.            cin>>a[i];  
16.        int l=0;  
17.        for( int i = 0 ; i < n ; ++i )  
18.            for( int j = 0 ; j < n ; ++j )  
19.                if( i != j && j > i )  
20.                    p[l++] = a[i] + a[j];  
21.        sort(p,p+l,cmp);  
22.        cout<<p[0];  
23.        for( int i = 1 ; i < k ; ++i )  
24.            cout<<‘ ‘<<p[i];  
25.        cout<<endl;  
26.    }  
27.    return 0;  
28.}  

 

小希的数表2(用的for循环)

标签:for   algorithm   pre   for循环   cout   return   nbsp   cin   sort   

原文地址:http://www.cnblogs.com/liunx1109/p/6187398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!