华为OJ基础篇-输入n个整数,输出其中最小的k个

输入n个整数,输出其中最小的k个

void HWoj(){
    int n = 0, m = 0;
    vector<int> num;
    cin >> n >> m;
    int k = 0,tmp=0;
    while (k <n){
        cin >> tmp;
        num.push_back(tmp);
        ++k;
    }
    sort(num.begin(), num.end());
    for (int i = 0; i < m; ++i){
        cout << num.at(i) << " ";
    }
    cout << endl;
}

你可能感兴趣的:(C++)