fork(1) 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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int t = Integer.parseInt(bf.readLine());
  13. while(t-->0){
  14. String s = bf.readLine();
  15. int l = 0; int r = 0; int p = 1;
  16. int res = 0;
  17. for(int i = 0, j = s.length()-1; i<=j; i++,j--){
  18. l = (l*p + s.charAt(i))%1000000009;
  19. r = (r*p + s.charAt(j))%1000000009;
  20. p *= 73;
  21. p %= 1000000009;
  22. if(l==r && i<j){
  23. res += 2;
  24. l = 0; r = 0; p = 1;
  25. }
  26. }
  27. if(p != 1)
  28. res++;
  29. System.out.println(res);
  30. }
  31. }
  32. }
Success #stdin #stdout 0.06s 380224KB
stdin
1
pastipas
stdout
1