0

Why wont pass 2 tests of 5??

import java.util.*; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String myName = sc.nextLine(); int nmAgent = sc.nextInt(); sc.nextLine(); String candi = sc.nextLine(); String[] clients = candi.split(" "); ArrayList<String> people = new ArrayList<String>(); for(int i = 0; i < clients.length; i++){ people.add(clients[i]); } people.add(myName); Collections.sort(people); int myI =(people.indexOf(myName)); int myTot = (int)Math.ceil((1 + myI)/ nmAgent); if(nmAgent > 1){ System.out.print(20 * myTot); } else if(nmAgent < 2){ System.out.print(((myI + 1) * 20) / nmAgent); } } }

21st Apr 2020, 9:54 AM
🔹Marko B.🔹
🔹Marko B.🔹 - avatar
8 Answers
0
If u calculate formula its what task is asking but still wont pass. What did i miss here 🤔
21st Apr 2020, 9:56 AM
🔹Marko B.🔹
🔹Marko B.🔹 - avatar
0
For the case: myl=0, first place according to your code, and nmagents=5 It returns 0.
21st Apr 2020, 11:11 AM
Jayakrishna 🇮🇳
0
if(myI == 0 && nmAgent > 1){ myI = 1; }
21st Apr 2020, 1:12 PM
🔹Marko B.🔹
🔹Marko B.🔹 - avatar
0
That doesnot fit for other cases.. Did you checked it..? Try to for other possible cases in code playground.. When person is in first or second place, and number of agents or 3 or 4 or 5, it is incorrect result 0. I didn't checked all,.. But a sample cases it returning zero so try it again..
21st Apr 2020, 2:07 PM
Jayakrishna 🇮🇳
0
Yes i see. Thank you
21st Apr 2020, 2:09 PM
🔹Marko B.🔹
🔹Marko B.🔹 - avatar
0
JayaKrishna how you know what is test asking if its hidden? It would be much better to see what test is asking or description should tell you about conditions. Then you know what task is asking from you.
21st Apr 2020, 2:35 PM
🔹Marko B.🔹
🔹Marko B.🔹 - avatar
0
I don't understand your reply clearly.. But if you are asking how to check is run it in playground.. Description says person may in 1 to 5 positions and number of agents are 1 to 5. So by these info we can check Program correctness, by inputing possible cases... Task is to write to satisfy all possible cases.. Your question is why not passing 2 out 5. So I checked it by sample cases and give a replys.. So. Test cases must be hidden otherwise one can easily hardcode solution for test cases.. Edit: Are you asking write solution?
21st Apr 2020, 2:50 PM
Jayakrishna 🇮🇳
0
Ok thank you
21st Apr 2020, 2:53 PM
🔹Marko B.🔹
🔹Marko B.🔹 - avatar