排序sort()函数
参考 : (8条消息) C++ sort()排序详解_晴空๓的博客-CSDN博客
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.
#include <iostream>
using namespace std;
#include <algorithm>
//下面是自作聪明
/*
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int n, k;
cin >> n >> k;
int* people = new int[n];
for (int i = 0; i < n; i++) cin >> people[i];
sort(people, people + n, cmp);
//for (int i = 0; i < n; i++) cout << people[i] << " ";
if (people[k - 1] <=0) {
cout << "0";
return 0;
}
int cnt_more = 0;
while (people[k + cnt_more] == people[k - 1]) cnt_more++;
cout << (k + cnt_more);
//排序到递减
//第k名如果等于0,输出0
//while(k+cnt的等于k) cnt++
//按照道理,我应该手搓一个排序算法
//但我不想搓
return 0;
}
*/
//tmd这跟排序没有一点关系
int main()
{
int n, k;
cin >> n >> k;
int* people = new int[n];
for (int i = 0; i < n; i++) {
cin >> people[i];
}
int K_people = people[k - 1];
int cnt = 0;
for (int i = 0; i < n; i++) {
if (people[i] >= K_people&&people[i]!=0) cnt++;
}
cout << cnt;
}