题解 | #输入n个整数,输出其中最小的k个#
输入n个整数,输出其中最小的k个
https://www.nowcoder.com/practice/69ef2267aafd4d52b250a272fd27052c
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main () { int n,k,num; cin >> n; cin >> k; vector<int>nums; while (n--){ while (cin >> num){ nums.push_back(num); } } sort(nums.begin(),nums.end()); for (int i = 0; i < k; i++){ cout << nums[i]<<" "; } cout <<endl; return 0; }