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 IOException
  11. {
  12. // your code goes here
  13. try{
  14. int t=Integer.parseInt(br.readLine());
  15. while(t--!=0){
  16. String s=br.readLine();
  17. int i=0;
  18. int n = (s.length()%2==0)?s.length()/2:s.length()/2+1;
  19. while(s.charAt(i)==s.charAt(s.length()-i-1) && i<n)
  20. i++;
  21. if(s.length()==0){
  22. System.out.println("NO");
  23. continue;
  24. }
  25. if(i==n){
  26. System.out.println("YES");
  27. continue;
  28. }
  29. String p=s.substring(0,i)+s.substring(i+1,s.length());
  30. boolean x=palindrome(p);
  31. if(x==true){
  32. System.out.println("YES");
  33. continue;
  34. }
  35. String q=s.substring(0,s.length()-i-1)+s.substring(s.length()-i,s.length());
  36. boolean y=palindrome(q);
  37. if(y==true){
  38. System.out.println("YES");
  39. continue;
  40. }
  41. else{
  42. System.out.println("NO");
  43. continue;
  44. }
  45.  
  46. }
  47. }catch(Exception e){
  48. return;
  49. }
  50.  
  51. }
  52. public static boolean palindrome(String s){
  53. int n = (s.length()%2==0)?s.length()/2:s.length()/2+1;
  54. int i=0;
  55. while(s.charAt(i)==s.charAt(s.length()-i-1) && i<n)
  56. i++;
  57. if(i==n)
  58. return true;
  59. else
  60. return false;
  61. }
  62. }
Success #stdin #stdout 0.07s 380160KB
stdin
1
x0y10
stdout
NO