#include <iostream>
#include <string>
using namespace std;
int find(string a[], int low, int high, string target){
int mid = low + (high-low)/2;
if (low > high)
return -1;
if (a[mid] == target)
return mid;
if (a[mid] == ""){
int tmp1 = mid -1 ;
int tmp2 = mid +1 ;
while (a[tmp1] == "" && tmp1>0)
tmp1--;
while (a[tmp2] == "" && tmp2 < 12)
tmp2++;
if (target <= a[tmp1]){
find(a, low, tmp1, target);
}else{
find(a, tmp2, high, target);
}
}
std::cout << "find did not return a value.\n" ;
}
int main(){
string s[13] = {"at", "", "", "", "ball", "", "", "car", "", "", "dad", "", ""};
cout<< find(s, 0, 12, "car");
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBmaW5kKHN0cmluZyBhW10sIGludCBsb3csIGludCBoaWdoLCBzdHJpbmcgdGFyZ2V0KXsKICAgIGludCBtaWQgPSBsb3cgKyAoaGlnaC1sb3cpLzI7CiAgICBpZiAobG93ID4gaGlnaCkKICAgIAlyZXR1cm4gLTE7CiAgICBpZiAoYVttaWRdID09IHRhcmdldCkKICAgIAlyZXR1cm4gbWlkOwogICAgCiAgICBpZiAoYVttaWRdID09ICIiKXsKICAgIAlpbnQgdG1wMSA9IG1pZCAtMSA7CiAgICAJaW50IHRtcDIgPSBtaWQgKzEgOwogICAgCXdoaWxlIChhW3RtcDFdID09ICIiICYmICB0bXAxPjApCiAgICAJICAgIHRtcDEtLTsKICAJICAgIHdoaWxlIChhW3RtcDJdID09ICIiICYmIHRtcDIgPCAxMikKICAJICAgICAgICB0bXAyKys7CiAgCSAgICBpZiAodGFyZ2V0IDw9IGFbdG1wMV0pewogIAkJZmluZChhLCBsb3csIHRtcDEsIHRhcmdldCk7CiAgCSAgICB9ZWxzZXsKICAJCWZpbmQoYSwgdG1wMiwgaGlnaCwgdGFyZ2V0KTsKICAJICAgIH0KICAJfQogIAkKICAJc3RkOjpjb3V0IDw8ICJmaW5kIGRpZCBub3QgcmV0dXJuIGEgdmFsdWUuXG4iIDsKIH0KCmludCBtYWluKCl7CglzdHJpbmcgc1sxM10gPSB7ImF0IiwgIiIsICIiLCAiIiwgImJhbGwiLCAiIiwgIiIsICJjYXIiLCAiIiwgIiIsICJkYWQiLCAiIiwgIiJ9OwoJY291dDw8IGZpbmQocywgMCwgMTIsICJjYXIiKTsKfQoK