标签: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.}
标签:for algorithm pre for循环 cout return nbsp cin sort
原文地址:http://www.cnblogs.com/liunx1109/p/6187398.html