fork download
  1. #include <iostream>
  2. #include <cctype>
  3.  
  4. char* del_even_words(char* s){
  5. int i = 1;
  6. char* a, *p, *t = s;
  7.  
  8. for(p = s; *s; *s = *p){
  9. if(! std::isalpha(*p)){
  10. if(*p == '.' || *p == '!' || *p == '?')
  11. i = 1;
  12. ++s;
  13. } else {
  14. a = p;
  15. while(std::isalpha(*a))
  16. ++a;
  17.  
  18. if((i & 1) == 0)
  19. p = a;
  20. else {
  21. while(p != a)
  22. *s++ = *p++;
  23. }
  24. ++i;
  25. continue;
  26. }
  27. ++p;
  28. }
  29. return t;
  30. }
  31.  
  32. int main(void){
  33. char s[] = "one two three! one two three four five.\n"\
  34. "{one} {two} {three} {four} {five} {six}...\n"\
  35. "Fox, dog, cat, bat!!!\n";
  36. std::cout << s << std::endl;
  37. std::cout << del_even_words(s) << std::endl;
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
one two three! one two three four five.
{one} {two} {three} {four} {five} {six}...
Fox, dog, cat, bat!!!

one  three! one  three  five.
{one} {} {three} {} {five} {}...
Fox, , cat, !!!