#include #include #include int expand(char *dst,char ch,int amount){ #define WRITE(s__) {int l__=strlen(s__); if(dst){memcpy(dst,s__,l__+1); dst+=l__;} written+=l__;} #define WGOTO(i__) {while(curpos"); curpos++;} while(curpos>i__){WRITE("<"); curpos--;}} #define WMOVE(i1__,i2__) {int p__=curpos; WGOTO(i1__); WRITE("[-"); WGOTO(i2__); WRITE("+"); WGOTO(i1__); WRITE("]"); WGOTO(p__);} int written=0,curpos=0; switch(str[i]){ case '+': //strcpy(p,"+>+[->+<]>[<<->>[-<+>]]<<"); p+=25; break; case '+': //strcpy(p,"+>+[<->[->+<]]>[-<+>]<<"); p+=23; break; case '+': WRITE("+"); for(int i=1;i"); } case '-': strcpy(p,"->[->+<]>[<<+>>[-<+>]]<-<"); p+=25; break; case '[': strcpy(p,"[->>+>>>+<<<<<]>>>>>[<<<[-<<+>>]+>>>[-]]<<<<[->+>>>+<<<<]>>>>[[-<<<-<+>>>>]<<<+>>>]<<<[[-]<<"); p+=92; break; case ']': strcpy(p,"[->>+>>>+<<<<<]>>>>>[<<<[-<<+>>]+>>>[-]]<<<<[->+>>>+<<<<]>>>>[[-<<<-<+>>>>]<<<+>>>]<<<]<<"); p+=89; break; case '>': strcpy(p,">>>"); p+=3; break; case '<': strcpy(p,"<<<"); p+=3; break; case ',': strcpy(p,"[-]>,<"); p+=6; break; case '.': strcpy(p,">.<"); p+=3; break; default: *(p++)=str[i]; break; } return res; #undef WRITE #undef WGOTO #undef WMOVE } int main(void){ int amount=1; char c; while((c=getchar())!=EOF){ if(c=='{'){ amount++; } else if(c=='}'){ amount--; if(amount<=0){ fprintf(stderr,"More '}' than '{'\n"); return 1; } } else if(amount==1){ putchar(c); } else { int len=expand(NULL,c,amount); char *str=malloc(len+1); expand(str,c,amount); printf("%s",str); free(str); } } }