C++,最短代码,进来学知识
输入n个整数,输出其中最小的k个
http://www.nowcoder.com/practice/69ef2267aafd4d52b250a272fd27052c
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
int main(){
int n,k;
while(cin>>n>>k){
vector<int> vec(n);
for(int i=0;i<n;++i)
cin>>vec[i];
partial_sort(vec.begin(),vec.begin()+k,vec.end());
copy(vec.begin(),vec.begin()+k,ostream_iterator<int>(cout," "));
cout<<endl;
}
}