- 1

TESTING TROUBLE T__T

import java.util.Scanner; public class Security { public static void main(String[] args) { Scanner input = new Scanner(System.in); String S1 = input.nextLine(); String S2 = S1.replaceAll("x",""); char [] A = S2.toCharArray(); if(A[1]=='G'){System.out.println("quiet");} else{System.out.println("ALARM");} } } My code just thought 5/6 test cases. So I can't gain 100 exp as expected. Could someone give me an advice. Thanks a lot.

25th Apr 2020, 9:19 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
9 Antworten
+ 1
Good one.. RnT.Lee But you lucky, if input contains like ex: "TGGG
quot;, it Alarms... Another approach is, read string, assign index values to G, T, $ variables and compare G is between or not.. Just saying for you to give a try that as practice.. Good luck for Next one...
27th Apr 2020, 2:14 PM
Jayakrishna 🇮🇳
+ 1
Smart logic.. But I think, problem may contains inputs of any number of Gurads.. Ex: GTG$
25th Apr 2020, 3:25 PM
Jayakrishna 🇮🇳
+ 1
RnT.Lee Check it in the code coach.. If not passed then reply here.. First approach is better but may not pass for G>1, so make it a special case. 2nd is also may works.. check ones.. Problem says to check G must be in between T&$ like T<G<$ or
lt;G<T. You may check it any way..
26th Apr 2020, 8:10 AM
Jayakrishna 🇮🇳
+ 1
RnT.Lee Congrats.. But your fisrt code is fine for this case.. Are you changed approach..?
27th Apr 2020, 11:10 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 Maybe... :((( I'll try again.
26th Apr 2020, 1:44 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
Jayakrishna🇮🇳 How about this code that just be modified: for(int i = 0; i<A.length; i++){ if(A[i]=='
#x27;){ if(A[i+1]=='T'||A[i-1]=='T') {System.out.println("ALARM");}else{System.out.println("quiet");}}}
26th Apr 2020, 2:17 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
Jayakrishna🇮🇳 Here my attempts: if(S2.contains("$GT")||S2.contains("TG
quot;)) {System.out.println("quiet");}else{System.out.println("ALARM");} But it just passed 5/6 test cases too.
27th Apr 2020, 9:30 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
@I'm done!! 😅 Test case No.6 that has the input is of the form "$GGGGT".
27th Apr 2020, 11:02 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
Jayakrishna🇮🇳 Here my attempts: if(S2.contains("$GT")||S2.contains("TG
quot;)||S2.contains("$GGGGT")) {System.out.println("quiet");}else{System.out.println("ALARM");} //There are only one "T" and one "
quot;, so the String just need to contains one of the substrings above. More over, my first code is just accidentally solved. It is not right for all of cases. Ex: GG$T or G$GT...
27th Apr 2020, 11:31 AM
Le Hoang Tuan
Le Hoang Tuan - avatar