-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmozilla.c
98 lines (95 loc) · 2.19 KB
/
mozilla.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define DEBUG if(0)
int main() {
char c[8];
int pos,back,fwd,enter;
pos = -1;
back = 0;
int ct = 0;
fwd = 0;
enter = -1;
while (1)
{
int z;
// for (int i = 0; i < 8; i++)
// {
// z = scanf("%c",&c[i]);
// DEBUG printf("[%c]",c[i]);
// if(c[i] == '\n') break;
// }
char* b = fgets(c,9,stdin);
//puts(c);
// back = 4
// forward = 7
// enter = 5
if(b == NULL)
{
//DEBUG printf("QUEBRA!\n");
break;
}
int q = strlen(c);
if (c[q-1] == '\n')
{
c[q-1] = '\0';
}
q = strlen(c);
//printf("%s\n",c);
fflush(stdin);
ct++;
switch (q)
{
case 4: //back
DEBUG printf("4 {%d} [%s] = %d\t\t",ct,c,q);
if(ct == 1 ) break;
if(pos == 0) break;
if (back>=0)
{
pos--;
back--;
fwd++;
enter--;
}
break;
case 7: //fwd
DEBUG printf("7 {%d} [%s] = %d\t\t",ct,c,q);
if (fwd != 0)
{
back++;
fwd--;
pos++;
break;
}
break;
case 5: //enter
DEBUG printf("5 {%d} [%s] = %d\t\t",ct,c,q);
if(enter == -1)
{
pos++;
enter++;
back = 0;
fwd = 0;
break;
}
if (pos == 0 && back == 0)
{
fwd = 0;
}
pos++;
enter++;
back++;
break;
default:
// DEBUG printf("{%d} [%s] = %d\t",ct,c,q);
// DEBUG printf("back:[%d] | fwd:[%d]\n",back,fwd);
DEBUG printf("DEFAULT.\n");
break;
}
DEBUG printf("back:[%d] | fwd:[%d] | pos:[%d]\n",back,fwd,pos);
}
printf("BACK: %d\n",back);
printf("FORWARD: %d\n",fwd);
return 0;
}