fork download
  1. #include <iostream>
  2. #include <cctype>
  3. #define is_delim(c) (ispunct((c)) || isspace((c)))
  4.  
  5. char* poli_end(char* s){
  6. char* a, *b, *p = NULL;
  7. int k = 0, n = 0;
  8. do {
  9. if(*s && !is_delim(*s))
  10. ++k;
  11. else if(k > 0){
  12. a = s - k;
  13. b = s - 1;
  14. while((a < b) && (*a == *b)){
  15. ++a;
  16. --b;
  17. }
  18. if(a >= b){
  19. p = s - k;
  20. n = k;
  21. }
  22. k = 0;
  23. }
  24. } while(*s++ != '\0');
  25.  
  26. if(p != NULL)
  27. *(p + n) = '\0';
  28. return p;
  29. }
  30.  
  31. int main(void){
  32. char s[] = "ada, wow, bla, kazak, end.";
  33. char* p = poli_end(s);
  34. if(p != NULL)
  35. std::cout << p << std::endl;
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
kazak