fork download
  1. #include <stdio.h>
  2.  
  3. int remove_area(char* s, char fc, char lc){
  4. int n, k;
  5. char* p, *i;
  6.  
  7. for(k = n = 0, p = s; *p; ++p){
  8. if(*p == fc){
  9. ++n;
  10. k = 1;
  11. } else if(*p == lc){
  12. --n;
  13. k = 1;
  14. }
  15. }
  16. if(n != 0 || !k)
  17. return 0;
  18.  
  19. while(*s && (*s != fc))
  20. ++s;
  21.  
  22. for(p = s; *s; *s = *p){
  23. if(*p != fc)
  24. ++s;
  25. else {
  26. *(++s) = *p;
  27. i = p + 1;
  28. while(*i && (*i != lc))
  29. ++i;
  30. p = i;
  31. continue;
  32. }
  33. ++p;
  34. }
  35. return 1;
  36. }
  37.  
  38. int main(void){
  39. char s[] = "(ops) sector (area) (2012)() end (X)";
  40.  
  41. puts(s);
  42. if(! remove_area(s, '(', ')') )
  43. puts("error");
  44. else
  45. puts(s);
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
(ops) sector (area) (2012)() end (X)
() sector () ()() end ()