fork(1) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5.  
  6. char* poly_rep(char* s, size_t N){
  7. char* p, *i, *o, *t = s;
  8. size_t k, l, n = strlen(s) + 1;
  9.  
  10.  
  11. while(*s){
  12. while(*s && ! isalnum(*s))
  13. ++s;
  14.  
  15. p = s + 1;
  16. while(isalnum(*p))
  17. ++p;
  18.  
  19. l = (size_t)(p - s);
  20. if(! (l % 2)){
  21.  
  22. i = p - 1;
  23. o = s;
  24. while((s < i) && (*s == *i)){
  25. ++s;
  26. --i;
  27. }
  28.  
  29. if(s > i){
  30. if((n + l + 1) >= N)
  31. break;
  32.  
  33. k = (size_t)(o - t);
  34. memmove(p + 1, o, (n - k) * sizeof(char));
  35. *p = ' ';
  36. p += l + 1;
  37. n += l + 1;
  38. }
  39. }
  40. s = p;
  41. }
  42. return t;
  43. }
  44.  
  45.  
  46. int main(void){
  47. char s[64] = "KOOK, wow [ABBA], bla 21LL12";
  48.  
  49. puts(s);
  50. puts( poly_rep(s, sizeof(s)- 1) );
  51. return 0;
  52. }
Success #stdin #stdout 0s 2052KB
stdin
Standard input is empty
stdout
KOOK, wow [ABBA], bla 21LL12
KOOK KOOK, wow [ABBA ABBA], bla 21LL12 21LL12