Your code is tested by a computer automatically, not by a human being, and you have to write your code accordingly.
For each problem, Codechef will have one or more input files, each according to the specifications mentioned in the problem statement, and corresponding correct output files. Codechef will run your program on each of the input files by redirecting the standard input stream to an input file, and the standard output stream to another file. The output generated by your program must match the correct output exactly in order to be judged correct.
Some consequences of this:
If your program starts by printing ‘Enter the number’ and the problem does not tell you to do so, then since this is not part of the correct output, you will be never be judged correct regardless of what the rest of your program does.
As all that matters is that the output files match, it makes no difference at all at what point in your program’s execution that this output is written. So there is no need to read all of the input before starting output; it is much more common to just print out each result as you are reading through the input.
If you use any method other than using the standard input and output streams - for example, using command line arguments, reading from a file, opening up some sort of dialog box, or otherwise - you will never be judged correct.
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N;
int t = br.read();
br.readLine();
for (int i = 0; i < t; i++) {
N = Integer.parseInt(br.readLine());
String s1 = br.readLine();
String s[] = s1.split(" ");
int a[] = new int[N];
for (int j = 0; j < N; j++) {
a[j] = Integer.parseInt(s[j]);
}
int K = Integer.parseInt(br.readLine());
int c = a[K - 1];
Arrays.sort(a);
for (int m = 0; m < N; m++) {
if (a[m] == c) {
System.out.println(m + 1);
break;
}
}
}
}
Your code is correct or not is determined by test case writtern by problem setter or experienced competitive coder and reviewed by various other coder.
When you submit your solution it feed specific input sets and test your output against its correct output files. Its all done in milliseconds by machine :);
Any amount of whitespace is considered equivalent to any other amount of whitespace. If you are asked to print one space between answers, and print three returns, 2 spaces, 4 tabs, and a few extra \r characters, that makes no difference.
public class skdhj
{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N;
int t = br.read();
br.readLine();
for (int i = 0; i < t; i++) {
N = Integer.parseInt(br.readLine());
String s1 = br.readLine();
String s[] = s1.split(" ");
int a[] = new int[N];
for (int j = 0; j < N; j++) {
a[j] = Integer.parseInt(s[j]);
}
int K = Integer.parseInt(br.readLine());
int c = a[K - 1];
Arrays.sort(a);
for (int m = 0; m < N; m++) {
if (a[m] == c) {
System.out.println(m + 1);
break;
}
}
}
}