Hello everyone, I noticed something weird when doing the following challenge:
I wrote the solution for the challenge in javascript and it got the manual test case to work correctly, however when I published it it said wrong answer: test cases failed.
the problem is that the failed test cases viewer is not supported with javascript.
I translated the code into pure java, and it worked perfectly:
JS:
importPackage(java.io);
importPackage(java.lang);
let reader = new BufferedReader( new InputStreamReader(System['in']) );
let t = parseInt(reader.readLine());
for (let i = 0; i<t; i++){
let s = String(reader.readLine());
let f = true;
for(let j = 0; j<s.length; j+=2){
if (s.substr(j, j+2)=="AA" || s.substr(j, j+2)=="BB"){
f = false;
}
}
print(f ? "yes" : "no");
}
Java:
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i<t; i++){
String s = sc.next();
//System.out.println(s);
boolean flag = true;
for (int j = 0; j<s.length(); j+=2){
if (s.substring(j, j+2).equals("AA")||s.substring(j, j+2).equals("BB")){
flag = false;
}
}
System.out.println(flag ? "yes" : "no");
}
}
}
Can anyone tell me why this problem occurs - am I missing something in my code or are there compatibility problems with javascript and the codechef servers? thanks in advance for the replies