// ConsoleApplication10.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class BinarySearch {
public:
int getPos(vector<int> A, int n, int val) {
// write code here
int beg = 0;
int end = n-1;
int mid = (beg + end) / 2;
int pos = -1;
while (beg<=end)
{
if (A[mid] == val)
{
--mid;
while (A[mid]==val && mid>=0)
{
--mid;
}
pos = mid + 1;
break;
}
else if (A[mid] < val)
{
beg = mid + 1;
mid= (beg + end) / 2;
}
else
{
end = mid - 1;
mid = (beg + end) / 2;
}
}
return pos;
}
};
int main()
{
vector<int> A = { 3,3,5,7,9 };
int n = 5, val = 3;
BinarySearch bs;
cout << bs.getPos(A, n, 3) << endl;
return 0;
};