- 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.
9 Respostas
+ 1
Good one.. RnT.Lee
But you lucky, if input contains like ex: "TGGGquot;, 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...
+ 1
Smart logic..
But I think, problem may contains inputs of any number of Gurads..
Ex:
GTG$
+ 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..
+ 1
RnT.Lee
Congrats..
But your fisrt code is fine for this case..
Are you changed approach..?
0
Jayakrishna🇮🇳 Maybe... :((( I'll try again.
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");}}}
0
Jayakrishna🇮🇳
Here my attempts:
if(S2.contains("$GT")||S2.contains("TGquot;)) {System.out.println("quiet");}else{System.out.println("ALARM");}
But it just passed 5/6 test cases too.
0
@I'm done!! 😅
Test case No.6 that has the input is of the form "$GGGGT".
0
Jayakrishna🇮🇳
Here my attempts:
if(S2.contains("$GT")||S2.contains("TGquot;)||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...