题解 | #输入n个整数,输出其中最小的k个#
输入n个整数,输出其中最小的k个
https://www.nowcoder.com/practice/69ef2267aafd4d52b250a272fd27052c
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int n, k; while (cin >> n >> k) { vector<int> vec; for (int i = 0; i < n; ++i){ int val; cin >> val; vec.push_back(val); } sort(vec.begin(),vec.end()); for (int i = 0; i < k; ++i){ cout << vec[i] << ' '; } cout << endl; } return 0; }#23届找工作求助阵地##我的实习求职记录##14天坚持打卡##零基础学习C++#