fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #define lli long long int
  5. using namespace std;
  6.  
  7. lli RevCount (char *s, lli f, lli l);
  8.  
  9. int main () {
  10.  
  11. char Word[30];
  12. int flag, i;
  13.  
  14. while (scanf ("%s",Word),strcmp (Word,"*END*")!=0)
  15. {
  16. flag = 0;
  17. for (i=1;i<strlen(Word); i++)
  18. { /* check each possibility */
  19. if (RevCount (Word,0,i-1) && RevCount (Word,i,strlen(Word)-1))
  20. {
  21. flag = 1;
  22. break;
  23. }
  24. }
  25. if (flag)
  26. printf ("%s YES\n",Word);
  27. else
  28. printf ("%s NO\n",Word);
  29. }
  30. return 0;
  31. }
  32.  
  33. lli RevCount (char *s, lli first, lli last) {
  34.  
  35. lli i, ct=0;
  36.  
  37. for (i=first; i < first+(last-first+1)/2; i++)
  38. ct += s[i] != s[first+last-i]; /* count differences */
  39. if(ct==1 || (ct==0 && (last-first)%2==0))
  40. return 1;
  41. else
  42. return 0;
  43.  
  44. }
Success #stdin #stdout 0s 2732KB
stdin
BATMAN
SUPERMAN
*END*
stdout
BATMAN YES
SUPERMAN NO