#include <iostream> void sort(int* a, int n) { int i, j, min, temp; for (i = 0; i < n - 1; i++) { min = i; for (j = i + 1; j < n; j++) if (a[j] > a[min]) min = j; temp = a[i]; a[i] = a[min]; a[min] = temp; } } int main() { int n, k; std::cin >> n >> k; if (n == k || n < k) { std::cout << k; return 0; } int* scores = new int[n]; for (int i=0; i<n; i++) std::cin >> scores[i]; sort(scores, n); while (k+1 < n) { if (scores[k-1] != scores[k]) break; k++; } std::cout << k; delete scores; return 0; }
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 33 34 35 36 37 38 39 | #include <iostream> void sort(int* a, int n) { int i, j, min, temp; for (i = 0; i < n - 1; i++) { min = i; for (j = i + 1; j < n; j++) if (a[j] > a[min]) min = j; temp = a[i]; a[i] = a[min]; a[min] = temp; } } int main() { int n, k; std::cin >> n >> k; if (n == k || n < k) { std::cout << k; return 0; } int* scores = new int[n]; for (int i=0; i<n; i++) std::cin >> scores[i]; sort(scores, n); while (k+1 < n) { if (scores[k-1] != scores[k]) break; k++; } std::cout << k; delete scores; return 0; } |