fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static int result;
  11. public static int recursion(String s, int l, int r){
  12. result++;
  13. if(l >= r) return 1;
  14. else if(s.charAt(l) != s.charAt(r)) return 0;
  15. else return recursion(s, l+1, r-1);
  16. }
  17.  
  18. public static int isPalindrome(String s){
  19. return recursion(s, 0, s.length()-1);
  20. }
  21.  
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. // your code goes here
  25. Scanner sc = new Scanner(System.in);
  26. int T = sc.nextInt();
  27. for(int i = 0; i < T; i++) {
  28. result = 0;
  29. System.out.println(isPalindrome(sc.next()) + " " + result);
  30. }
  31. sc.close();
  32. }
  33. }
Success #stdin #stdout 0.17s 45692KB
stdin
5
AAA
ABBA
ABABA
ABCA
PALINDROME
stdout
1 2
1 3
1 3
0 2
0 1