-
Notifications
You must be signed in to change notification settings - Fork 1
/
brain.c
75 lines (57 loc) · 1.04 KB
/
brain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <string.h>
#define MEMSIZE 30000
#define INBUF 100000
int main(void)
{
unsigned char buffer_entrada[INBUF];
unsigned char memoria[MEMSIZE];
int ptr_in, ptr_mem, len_in;
int n, i;
char c;
scanf ("%d", &n);
for (i = 1; i <= n; i++)
{
printf ("Instancia %d\n", i);
ptr_in = 0;
ptr_mem = 0;
bzero(memoria, MEMSIZE);
scanf("%s%*[\r\n]", buffer_entrada);
len_in = strlen(buffer_entrada);
while ((scanf ("%c", &c) != EOF) && (c != '\n'))
{
switch (c)
{
case '>':
ptr_mem++;
break;
case '<':
ptr_mem--;
break;
case '+':
memoria[ptr_mem]++;
break;
case '-':
memoria[ptr_mem]--;
break;
case '.':
putc(memoria[ptr_mem], stdout);
break;
case ',':
if (ptr_in < len_in)
memoria[ptr_mem] = buffer_entrada[ptr_in++];
else
memoria[ptr_mem] = 0;
break;
case '[':
break;
case ']':
break;
case '#':
break;
}
}
printf ("\n\n");
}
return 0;
}