水一波题解。。
我不会告诉你我没看见输出NO RESULT
所以WA了两次。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <cstdio> #include <algorithm> #define MAXN 10000 + 1 using namespace std; int N, k; int a[MAXN]; int (int argc, char **argv) { ios::sync_with_stdio(false); cin >> N >> k; for (register int i = 1; i <= N; ++i) cin >> a[i]; sort(a + 1, a + N + 1); if (k == 1) { cout << a[1] << endl; return 0; } int kth = 1; for (register int i = 2; i <= N; ++i) { if (a[i] != a[i - 1]) kth++; if (kth == k) { cout << a[i] << endl; return 0; } } cout << "NO RESULT" << endl; return 0; }
|
近期评论