fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4.  
  5. int solve(char c[]){
  6. int d = c[0] - '0', cuoi = c[strlen(c) - 1] - '0';
  7. if(!(d == 2 * cuoi || cuoi == 2 * d)) return 0;
  8. int l = 1, r = strlen(c) - 2;
  9. while(l < r){
  10. if(c[l] != c[r])
  11. return 0;
  12. ++l; --r;
  13. }
  14. return 1;
  15. }
  16.  
  17. int main(){
  18. int t; scanf("%d", &t);
  19. while(t--){
  20. char c[20];
  21. scanf("%s",c);
  22. if(solve(c))
  23. printf("YES\n");
  24. else printf("NO\n");
  25. }
  26. }
Success #stdin #stdout 0s 5400KB
stdin
3
45677658
123322
4888888
stdout
YES
YES
YES