-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLlaves_Alicia.cpp
More file actions
54 lines (51 loc) · 1.34 KB
/
Llaves_Alicia.cpp
File metadata and controls
54 lines (51 loc) · 1.34 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
#include<iostream>
#include<map>
using namespace std;
int main(){
map<int,int> puertas;
map<int,int> llaves;
int n1 = 0;
int contador1 = 0;
cin >> n1;
for(int i =0; i < n1; i++){
int puerta = 0;
contador1 = contador1 + 1;
cin >> puerta;
puertas[contador1] = puerta;
}
int n2 = 0;
int contador2 = 0;
cin >> n2;
for(int i =0; i < n2; i++){
int llave = 0;
contador2 = contador2 + 1;
cin >> llave;
llaves[contador2] = llave;
}
bool check = true;
int posicion = puertas.size()/2 + 1;
int menor = 0;
int mayor = puertas.size();
for(int i = 1; i < n2 + 1; i++){
while(check){
if((llaves[i] =! puertas[posicion]) && mayor == menor){
cout << 0 << endl;
check = false;
}
else if(llaves[i] == puertas[posicion]){
cout << posicion;
check = false;
}
else if(llaves[i] > puertas[posicion]){
menor = posicion;
posicion = posicion + (mayor - posicion)/2;
continue;
}
else if(llaves[i] < puertas[posicion]){
mayor = posicion;
posicion = (mayor - menor)/2;
continue;
}
}
}
}