imran.pavel's blog

By imran.pavel, 11 years ago, In English

This is the problem: http://codeforces.me/problemset/problem/158/A

The following code is my solution:

package practice; import java.util.*;

public class Practice { public static void main(String args[]) { int NContestants, Counter, KthContestant, i; int Input[]; Input = new int[55];

    Scanner InputReader = new Scanner(System.in);
    while(InputReader.hasNextInt())
    {
       NContestants = InputReader.nextInt();
       KthContestant = InputReader.nextInt();

       for(i=0; i<NContestants; i++)
       {
         Input[i] = InputReader.nextInt();
       }

       Counter = 0;
       for(i=0; i<NContestants; i++)
       {
         if(Input[i] >= Input[KthContestant - 1] && Input[i]!=0)
         {
          Counter++;
         }
       }

       System.out.println(Counter);
    }

    //InputReader.close();
}

}

Using same idea I got accepted when the solution is written in C++. But in Java why is it showing runtime error ?

  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?