Search for the number in the array and find the Array
There is an int-type array, and the difference between each two adjacent numbers is not 1 or-1. Given a number, we need to find the position of this number in the array.
In fact, the idea is to skip the search, because you know a number, then the second number is 1 at most, and the third number is 2 at most, however, you can use the number of targets minus this number to exclude unnecessary searches. For example, if the number you want is 10 and the first number is 2, the first seven numbers cannot reach 10 in any case, it is only possible to count at 8th, so we can directly judge the number at 8th.
The following is an example of how other people's code borrowed:
Void PrintfArray (int a [], int n) {for (int I = 0; I <n; I ++) printf ("% d", a [I]); putchar ('\ n');} int FindNumberInArray (int arr [], int n, int find_number) {int next_arrive_index = abs (find_number-arr [0]); while (rows <n) {if (arr [next_arrive_index] = find_number) return next_arrive_index; next_arrive_index + = abs (find_number-arr [next_arrive_index]);} return-1 ;}