fork(1) download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. int palin(char *a)
  9. {
  10. long long int i,k;
  11.  
  12. k = strlen(a);
  13.  
  14. for (i = 0; i < k / 2; ++i) {
  15. if (a[i] != a[k-i-1])
  16. return 0;
  17. }
  18.  
  19. return 1;
  20. }
  21.  
  22. int main() {
  23. // your code goes here
  24. long long int tcase,i,j = 0;
  25. char prsnt,prev,space;
  26.  
  27. scanf("%lld", &tcase);
  28. scanf("%c", &prev);
  29.  
  30. while (j < tcase) {
  31.  
  32. i = 0;
  33. char *a = NULL;
  34. a = (char *)calloc(2,sizeof(char));
  35.  
  36. while (1) {
  37. scanf("%c", &prsnt);
  38.  
  39. if (prsnt == 10) {
  40. a[i] = '\0';
  41. break;
  42. }
  43. if (i == 0 || (i > 0 && (prsnt != prev))) {
  44.  
  45. a[i] = prsnt;
  46. a = (char *)realloc(a,1);
  47. ++i;
  48. prev = prsnt;
  49. }
  50. }
  51. ++j;
  52.  
  53. if (palin(a))
  54. printf("YES\n");
  55. else
  56. printf("NO\n");
  57. free(a);
  58. }
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0s 2820KB
stdin
5
aba
aabaaa
aabbba
aaab
abca
stdout
YES
YES
YES
NO
NO