#include <iostream>
char* str_drep(char* s, char fc, char lc, char c){
int n;
char* p, *i, *t = s;
while(*s && (*s != fc))
++s;
for(p = s; *s; *s = *p){
if(*p == fc){
n = 1;
i = p + 1;
while(*i){
if(*i == fc)
++n;
else if(*i == lc){
if(--n == 0)
break;
}
++i;
}
if(! *i || n > 0){
while((*s = *p) != 0){
++s;
++p;
}
break;
} else if((i - p) > 1){
*s++ = *p++;
*s++ = c;
p = i;
continue;
}
}
++s;
++p;
}
return t;
}
int main(void){
char s[] = "()(lisp)(((prolog)))(-(!(#(COBOL)).)-)(D)";
std::cout << s << std::endl;
std::cout << str_drep(s, '(', ')', ' ') << std::endl;
return 0;
}