-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeb2_2easy.cpp
More file actions
65 lines (55 loc) · 1.54 KB
/
Copy pathcodeb2_2easy.cpp
File metadata and controls
65 lines (55 loc) · 1.54 KB
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
#include <iostream>
int EnemigoCercano(int arr[], int longuitud){
int x = 0;
int i = 0;
int salida;
while(i<longuitud && x!=-1){
if(arr[i]==1){
std::cout << "Posición de jugador: " << i << std::endl;
x = -1;
int k = i;
int y = 0;
int posd;
while(k<longuitud && y!=-1){
if(arr[k] == 2){
y = -1;
posd = k-i;
std::cout << "Enemigo a " << posd << " posiciones a la derecha"<< std::endl;
}
k++;
}
int j = i;
int z = 0;
int posi;
while(j>=0 && z!=-1){
if(arr[j] == 2){
z = -1;
posi = i -j;
std::cout << "Enemigo a " << posi << " posiciones a la izquierda"<< std::endl;
if(posd>posi){
salida = posi;
return salida;
}
if(posi>posd){
salida = posd;
return salida;
}
if(posi==posd){
salida = posd;
return salida;
}
}
j--;
}
}
i++;
}
return salida;
}
int main(){
int arr[6] = {0, 1, 0, 2, 0, 0}; // se puede cambiar este agreglo!
int longuitud = sizeof(arr) / sizeof(*arr);
int s = EnemigoCercano(arr, longuitud);
std::cout << "Enemigo más cercano a " << s << " posiciones"<< std::endl;
return 0;
}