fork download
  1. #include <stdio.h>
  2. #include<string.h>
  3.  
  4. int main(void) {
  5. long long int t,n,l,j,i,k,m;
  6. char a[100011];
  7. scanf("%lld",&t);
  8. while(t--){
  9. k=0;
  10. scanf("%s",a);
  11. l=strlen(a);
  12. i=0;
  13. j=l-1;
  14. m=0;
  15. while(i<=j){
  16. if(a[i]==a[j]){
  17. i++;j--;
  18. }
  19. else{
  20. m++;
  21. if(m>1) break;
  22. if((a[i+1]==a[j]) && ((i+2>=j-1)||a[i+2]==a[j-1])){
  23. i++;
  24. }
  25. else if((a[i]==a[j-1]) && ((j-2>=i+1)||a[j-2]==a[i+1])){
  26. j--;
  27. }
  28. else{
  29. m++;
  30. }
  31. }
  32. }
  33. if(m<=1){
  34. printf("YES - %s\n", a);
  35. }
  36. else printf("NO\n");
  37. }
  38. // your code goes here
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 3344KB
stdin
59
X010
0X10
01X0
010X
X0110
0X110
01X10
011X0
0110X
YX010
XY010
X0Y10
X01Y0
X010Y
Y0X10
0YX10
0XY10
0X1Y0
0X10Y
Y01X0
0Y1X0
01YX0
01XY0
01X0Y
Y010X
0Y10X
01Y0X
010YX
010XY
YX0110
XY0110
X0Y110
X01Y10
X011Y0
X0110Y
Y0X110
0YX110
0XY110
0X1Y10
0X11Y0
0X110Y
Y01X10
0Y1X10
01YX10
01XY10
01X1Y0
01X10Y
Y011X0
0Y11X0
01Y1X0
011YX0
011XY0
011X0Y
Y0110X
0Y110X
01Y10X
011Y0X
0110YX
0110XY
stdout
YES - X010
YES - 0X10
YES - 01X0
YES - 010X
YES - X0110
YES - 0X110
YES - 01X10
YES - 011X0
YES - 0110X
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES - X01Y10
NO
NO
NO
NO
NO
YES - 0X1Y10
NO
NO
YES - Y01X10
YES - 0Y1X10
YES - 01YX10
YES - 01XY10
YES - 01X1Y0
YES - 01X10Y
NO
NO
YES - 01Y1X0
NO
NO
NO
NO
NO
YES - 01Y10X
NO
NO
NO