You are viewing a single comment's thread. Return to all comments →
Below is my solution, initially
boolean funny = true;
declaration was outside the while loop which was failing 8 test cases. I declared the variable inside the while loop & all the cases passed.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numOfStrings = Integer.parseInt(br.readLine()); String s; StringBuilder reverse; while((s=br.readLine())!=null){ boolean funny = true; reverse = new StringBuilder(s).reverse(); for(int i=1;i<s.length();i++){ System.out.println(s.charAt(i)); int modS = Math.abs(s.charAt(i)-s.charAt(i-1)); int modR = Math.abs(reverse.charAt(i)-reverse.charAt(i-1)); if(modS!=modR){ funny = false; break; } } if(funny){ System.out.println("Funny"); }else{ System.out.println("Not Funny"); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Funny String
You are viewing a single comment's thread. Return to all comments →
Below is my solution, initially
declaration was outside the while loop which was failing 8 test cases. I declared the variable inside the while loop & all the cases passed.