题解 | #输入n个整数,输出其中最小的k个#
输入n个整数,输出其中最小的k个
https://www.nowcoder.com/practice/69ef2267aafd4d52b250a272fd27052c
#include<iostream> #include <set> using namespace std; int main() { int n, k; while(cin >> n >> k) { multiset<int> num; int count = 0; int temp = 0; for(int i = 0; i < n; i++) { cin >> temp; num.insert(temp); } for(auto x : num) { cout << x << " "; count++; if(count == k) break; } } return 0; }