+ 1
I still fail test case 4 in New Driver's License,why?
import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String me=sc.nextLine(); int agent=sc.nextInt(); String pe=sc.next(); ArrayList<String>people=new ArrayList<String>(5); for(int i=1;i<=4;i++){ people.add(pe); } people.add(me); Collections.sort(people); int myturn=people.indexOf(me); int res=(myturn/agent)*20+20; System.out.println(res); } }
3 Antworten
+ 1
I can't thank you enough for your response.
I found what's wrong.
0
If it is from SL code coach, I think 3rd input contains 4 words separated by space. First input is singles word.. So swap those way of taking input. Either take pe = sc.next() ; inside loop before adding to list.
0
Side comment: use more descriptive names for variables, methods, etc. You will thank yourself when making changes some time later or writing more complex code.