+ 1

New Driver's License 1 test case problem

My code solved every test cases but I don't understand why one of them is failed? I'll be really appreciated if someone can help me. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String name = sc.next(); int numOfAgents = sc.nextInt(); String p1=sc.next(), p2=sc.next(), p3=sc.next(), p4=sc.next(); String[] others = {p1,p2,p3,p4}; int numberInLine=1; for(int i=0;i<others.length;i++){ if(name.charAt(0) > others[i].charAt(0)) numberInLine++; } System.out.println((Math.abs(numberInLine - numOfAgents))*20 + 20); sc.close(); } }

29th Feb 2020, 7:01 PM
Mohammadyar Barandov
Mohammadyar Barandov - avatar
1 Resposta
0
Actually I find the problem and that is: if we have 4 agents and our name become third in the queue, then my code would print 40 and that's wrong because it should print 20. So I add the code below, before the last System.out.println, and I get the whole points. if (numOfAgents > numberInLine) System.out.println(20);
29th Feb 2020, 7:36 PM
Mohammadyar Barandov
Mohammadyar Barandov - avatar