-->
当前位置:首页 > 题库

PROGRAMMING:Binary search

Luz5年前 (2021-05-10)题库478
Input n value (1 < = n < = 1000), n non descending integers and the number x to be searched, use * * binary search algorithm * * to search for X, and output the subscript (0 ~ n-1) of X and the number of comparisons. If X does not exist, output - 1 and the number of comparisons.
###Input format:
Input three lines:
The first line is n-value;
The second line is n integers;
The third line is the x value.
###Output format:
Output the subscript (0 ~ n-1) of X and the number of comparisons. If X does not exist, output - 1 and the number of comparisons.
###Input example:
```in
four
1 2 3 4
one
```
###Output example:
```out
0
two
```






answer:If there is no answer, please comment