-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
tsetse.cpp
110 lines (98 loc) · 1.8 KB
/
tsetse.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n1, n2, x, instance = 1;
cin >> n1 >> n2;
while (n1 + n2 != 0) {
if (n1 == 0 || n2 == 0) {
cout << "Instancia " << instance << endl;
cout << "sim" << endl;
} else {
vector<int> v;
vector< vector<int> > matrix;
for (int i = 0; i < n1; ++i) {
for (int j = 0; j < n2; ++j) {
cin >> x;
v.push_back(x);
}
matrix.push_back(v);
v.clear();
}
int n, i = 0, j = 0, counter = 1;
while (true) {
n = matrix[i][j];
if (n == 1) {
if (i == 0) {
break;
} else {
matrix[i][j] = 0;
i--;
}
} else if (n == 2) {
if (i == 0 || j == n2-1) {
break;
} else {
matrix[i][j] = 0;
i--;
j++;
}
} else if (n == 3) {
if (j == n2-1) {
break;
} else {
matrix[i][j] = 0;
j++;
}
} else if (n == 4) {
if (j == n2-1 || i == n1-1) {
break;
} else {
matrix[i][j] = 0;
j++;
i++;
}
} else if (n == 5) {
if (i == n1-1) {
break;
} else {
matrix[i][j] = 0;
i++;
}
} else if (n == 6) {
if (j == 0 || i == n1-1) {
break;
} else {
matrix[i][j] = 0;
j--;
i++;
}
} else if (n == 7) {
if (j == 0) {
break;
} else {
matrix[i][j] = 0;
j--;
}
} else if (n == 8) {
if (j == 0 || i == 0) {
break;
} else {
matrix[i][j] = 0;
j--;
i--;
}
}
counter++;
if (matrix[i][j] == 0) break;
}
cout << "Instancia " << instance << endl;
if (counter == n1 * n2) cout << "sim" << endl;
else cout << "nao" << endl;
}
cin >> n1 >> n2;
if (n1 + n2 != 0) cout << endl;
instance++;
}
return 0;
}