- 2

TEST CASE TROUBLE T__T

import java.util.Scanner; import java.util.StringTokenizer; import java.util.ArrayList; import java.util.Collections; public class Waiting { public static void main(String[] args) { Scanner input = new Scanner(System.in); String N = input.next(); int n = input.nextInt(); String oN = input.nextLine(); String S = oN + " "+ N; StringTokenizer S1 = new StringTokenizer(S); ArrayList<String> A = new ArrayList<String>(S.length()); int j = 0; while(S1.hasMoreTokens()){ A.add(S1.nextToken()); j++; } Collections.sort(A); float m = 0; for(int i = 0; i<A.size(); i++){ if(N.equals(A.get(i))){ m = 20 +(20*i/n);} } System.out.println((int)m); } } My code can't pass the test 1 'cause the output is supposed =20. But I entered the input when running the code on my laptop, its output is 100 as expect.Help me, please

15th Apr 2020, 10:00 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
29 odpowiedzi
+ 3
Stephan Description link... https://www.sololearn.com/coach/18?ref=app RnT.Lee I checked your code with changes I specified, it working... Just add that extra line...
15th Apr 2020, 11:17 AM
Jayakrishna 🇮🇳
0
You mean output you getting is 20 but required is 100?
15th Apr 2020, 10:26 AM
Jayakrishna 🇮🇳
0
Hi. You didn't write puzzle statement. I cannot find mistake if I don't know what program should do.
15th Apr 2020, 10:33 AM
Stephan
Stephan - avatar
0
Jayakrishna🇮🇳 My code's output is 100, that's true. But evaluated output is 20! I don't know the reason. @@
15th Apr 2020, 10:54 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
That could be either test case bug or logical mistake in your code. Provide the problem statement.
15th Apr 2020, 10:57 AM
Stephan
Stephan - avatar
0
Stephan I just can write the title in the tag. Because the limitation of characters. @@
15th Apr 2020, 10:58 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
RnT.Lee There Expexted output is 100. Your code output is 100. Then what is problem? What is that evaluated output? There is confusion in your statements.. Actually, your getting output 20, Expexted output is 100. Because, there after reading output by nextInt() input pointer not goes to next line but input is in next line.. So Put like this... .. int n = input.nextInt(); input.nextLine(); //just add this... ....
15th Apr 2020, 11:00 AM
Jayakrishna 🇮🇳
0
Make screenshot
15th Apr 2020, 11:00 AM
Stephan
Stephan - avatar
0
Stephan my code through almost of test cases but the No.1!
15th Apr 2020, 11:02 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
Jayakrishna🇮🇳 i see... In my laptop I inserted a statement: Scanner input2 = new Scanner(System.in); Then use it to read a String of text. Outcome is 100. But I can't apply the same way in Sololearn App. @@
15th Apr 2020, 11:10 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
Try to print out variables to see their contents in test runner.
15th Apr 2020, 11:12 AM
Stephan
Stephan - avatar
0
RnT.Lee In lap you press enter, explicitly specify in line line input, but here its run according to methods... Check by changing code as I mentioned.. And see result.. If any errors then reply again.. Edit : you can share the description link
15th Apr 2020, 11:13 AM
Jayakrishna 🇮🇳
0
Stephan how can I sending the screenshot? @@ I'm using smartphone. And I can't see that function.
15th Apr 2020, 11:14 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
Through some cloud (imgur.com a.e.)
15th Apr 2020, 11:15 AM
Stephan
Stephan - avatar
0
Jayakrishna🇮🇳 yeah, it worked... :v but now the test cases 3 and 4 is wrong. I have no idea.. @@
15th Apr 2020, 11:29 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
I've just solved. 2 agents cannot share one client
15th Apr 2020, 11:34 AM
Stephan
Stephan - avatar
0
RnT.Lee Now you should think about your logic in m=20 + (20*i/n); For ex: If n=5, N=Zzz (last person) then i=4 So 20+(20*4/5) = 20+16=36 not the correct one.. Expected output is 100 Try and reply..
15th Apr 2020, 11:34 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 I've tried to figure out a general formula. Here are my attempts: When n=1: m= 20+ 20*i; n=2 & i mod 2=0: m= 20+ 20*i/n; n=2 & i is a odd number: m= 20+ 20*(i-1)/n;
16th Apr 2020, 8:46 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
RnT.Lee there is simpler solution. Just wrap i/n into Math.ceil
16th Apr 2020, 9:34 AM
Stephan
Stephan - avatar
0
Stephan I just realize it!! When n>=3 : m= 20+ Math.round((i-1)/n))*20;
16th Apr 2020, 9:41 AM
Le Hoang Tuan
Le Hoang Tuan - avatar