#include <stdio.h>
#include <stdlib.h>
char* read_string(size_t *size){
char *str;
int c;
size_t length = 0;
str
= realloc(NULL
, sizeof(char)*(*size
)); if(!str)return str;
while((c
=getchar()) != EOF
&& c
!= '\n'){ str[length++] = c;
if(length == *size) {
str
= realloc(str
, sizeof(char)*(*size
+= 10)); if(!str)
return str;
}
}
str[length++] = '\0';
size = length;
return str;
}
int main() {
int n;
char tape[10000];
for (int k = 0; k < n; k++)
tape[k] = 0;
int pointer = 0;
size_t length = 100;
char *program = read_string(&length);
for (unsigned int i = 0; i < length; i++) {
if (program[i] == '>')
pointer++;
if (program[i] == '<')
pointer--;
if (program[i] == '+')
tape[pointer]++;
if (program[i] == '-')
tape[pointer]--;
if (program[i] == '.')
if (program[i] == ',')
scanf("%c", &tape
[pointer
]);
if (program[i] == '[') {
if (tape[pointer] == 0) {
int counter = 1;
while (counter > 0) {
i++;
if (program[i] == '[')
counter++;
if (program[i] == ']')
counter--;
}
}
}
else if (program[i] == ']') {
if (tape[pointer] != 0) {
int counter = 1;
while (counter > 0) {
i--;
if (program[i] == '[')
counter--;
if (program[i] == ']')
counter++;
}
}
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmNoYXIqIHJlYWRfc3RyaW5nKHNpemVfdCAqc2l6ZSl7CiAgICBjaGFyICpzdHI7CiAgICBpbnQgYzsKICAgIHNpemVfdCBsZW5ndGggPSAwOwogICAgc3RyID0gcmVhbGxvYyhOVUxMLCBzaXplb2YoY2hhcikqKCpzaXplKSk7CiAgICBpZighc3RyKXJldHVybiBzdHI7CiAgICB3aGlsZSgoYz1nZXRjaGFyKCkpICE9IEVPRiAgJiYgIGMgIT0gJ1xuJyl7CiAgICAgICAgc3RyW2xlbmd0aCsrXSA9IGM7CiAgICAgICAgaWYobGVuZ3RoID09ICpzaXplKSB7CiAgICAgICAgCXN0ciA9IHJlYWxsb2Moc3RyLCBzaXplb2YoY2hhcikqKCpzaXplICs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V0gPT0gJ1snKQoJCQkJCQljb3VudGVyKys7CgkJCQkJaWYgKHByb2dyYW1baV0gPT0gJ10nKQoJCQkJCQljb3VudGVyLS07CgkJCQl9CgkJCX0KICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAocHJvZ3JhbVtpXSA9PSAnXScpIHsKCQkJaWYgKHRhcGVbcG9pbnRlcl0gIT0gMCkgewoJCQkJaW50IGNvdW50ZXIgPSAxOwoJCQkJd2hpbGUgKGNvdW50ZXIgPiAwKSB7CgkJCQkJaS0tOwoJCQkJCWlmIChwcm9ncmFtW2ldID09ICdbJykKCQkJCQkJY291bnRlci0tOwoJCQkJCWlmIChwcm9ncmFtW2ldID09ICddJykKCQkJCQkJY291bnRlcisrOwoJCQkJfQoJCQl9CiAgICAgICAgfQogICAgfQoKCXJldHVybiAwOwp9
MTAwCisrKysrKysrKytbJmd0OysrKysrKysmZ3Q7KysrKysrKysrKyZndDsrKysmZ3Q7KyZsdDsmbHQ7Jmx0OyZsdDstXSZndDsrKy4mZ3Q7Ky4rKysrKysrLi4rKysuJmd0OysrLiZsdDsmbHQ7KysrKysrKysrKysrKysrLiZndDsuKysrLi0tLS0tLS4tLS0tLS0tLS4mZ3Q7Ky4mZ3Q7Lg==
100
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.