题解 | #找到数组里的第k大数(C++)#
找到数组里的第k大数(C++)
https://www.nowcoder.com/practice/2d5e11b766654104ac91a54fe3a9f5db
#include<bits/stdc++.h> #include<vector> #include<algorithm> using namespace std; int main(){ int n,k; int m; vector<int>a; // write your code here...... cin>>n>>k; for(int i=0;i<n;i++) { cin>>m; a.push_back(m); } sort(a.begin(),a.end()); auto it=a.begin(); cout<<*(it+k-1)<<endl; return 0; }