题解 | #查找第K小数#
查找第K小数
https://www.nowcoder.com/practice/204dfa6fcbc8478f993d23f693189ffd
#include <iostream> #include <algorithm> using namespace std; const int N = 1001; int a[N]; int main() { int n; while(cin >> n){ for(int i = 0; i < n; i ++) cin >> a[i]; sort(a, a + n); int num; cin >> num; int k = 1; int i = 0; while(i < n){ if(i != 0 && a[i] > a[i - 1]){ k ++; } if(k == num){ cout << a[i] << endl; break; } i ++; } } return 0; } // 64 位输出请用 printf("%lld")