My issue
give explanation and some solution
My code
import java.util.Scanner;
class Codechef {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read the number of test cases
int T = 0;
if (scanner.hasNextInt()) {
T = scanner.nextInt();
}
for (int t = 0; t < T; t++) {
// Check if there is another integer to read
if (scanner.hasNextInt()) {
int X = scanner.nextInt();
int minIncorrect = Integer.MAX_VALUE;
// Iterate over possible number of correct answers
for (int c = 0; c <= 100; c++) {
int i = 3 * c - X;
if (i >= 0 && c + i <= 100) {
minIncorrect = Math.min(minIncorrect, i);
}
}
System.out.println(minIncorrect);
} else {
System.out.println("Input error");
}
}
scanner.close();
}
}
Learning course: Design and Analysis of Algorithms
Problem Link: https://www.codechef.com/learn/course/kl-daa/KLDAA24PRE02/problems/PREQ22