这题要仔细阅读题目的意思!就是这就句话“"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.”
注意一定要是正数,对于0,只能是大于,而对于不是0来说,就可以是大于或者等于!代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int n,k,i,sum;
int a[55];
while(scanf("%d%d",&n,&k)!=EOF)
{
for(i=1; i<=n; i++)
scanf("%d",&a[i]);
int sum=0;
if(a[k]!=0)
{
for(i=1; i<=n; i++)
{
if(a[i]>=a[k])
sum++;
}
}
else
{
for(i=1; i<=n; i++)
{
if(a[i]>a[k])
sum++;
}
}
printf("%d\n",sum);
}
return 0;
}