158A. Next Round
Problem Link: https://codeforces.com/problemset/problem/158/A
Solution 1:
import java.util.*;
public class A158 {
public static Scanner scn = new Scanner(System.in);
public static int passedStudent(int[] arr, int value, int k) {
int counter = 0;
for (int i = 0; i < arr.length; i++) {
if (value <= arr[i] && arr[i] > 0)
counter++;
else
return counter;
}
return counter;
}
public static void input(int[] arr) {
for (int i = 0; i < arr.length; i++)
arr[i] = scn.nextInt();
}
public static void main(String[] argv) {
int n = scn.nextInt();
int k = scn.nextInt();
int[] arr = new int[n];
input(arr);
if (arr[0] == 0)
System.out.println(0);
else
System.out.println(passedStudent(arr, arr[k - 1], k));
}
}
No comments:
Post a Comment
Thanks