#include <stdio.h>
#define N 140
int arr[N]= {
3887, 3874, 3860, 3845, 3830, 3813, 3796, 3778, 3760, 3740, // -29~-20
3720, 3698, 3676, 3653, 3629, 3604, 3578, 3551, 3524, 3495, // -19~-10
3465, 3435, 3403, 3371, 3337, 3303, 3267, 3231, 3194, 3156, // -9~0
3118, 3078, 3038, 2997, 2955, 2913, 2870, 2826, 2782, 2738, // 1~10
2693, 2648, 2602, 2556, 2510, 2464, 2417, 2371, 2324, 2278, // 11~20
2231, 2185, 2139, 2093, 2048, 2002, 1957, 1913, 1868, 1825, // 21~30
1781, 1739, 1697, 1655, 1614, 1574, 1534, 1495, 1456, 1419, // 31~40
1382, 1346, 1310, 1275, 1241, 1208, 1175, 1143, 1112, 1081, // 41~50
1052, 1023, 994, 967, 940, 914, 888, 863, 839, 815, // 51~60
792, 770, 748, 727, 707, 687, 668, 649, 631, 613, // 61~70
596, 579, 563, 547, 532, 517, 502, 488, 475, 462, // 71~80
449, 436, 424, 413, 401, 390, 380, 369, 359, 350, // 81~90
340, 331, 322, 314, 305, 297, 289, 282, 274, 267, // 91~100
260, 253, 247, 240, 234, 228, 222, 217, 211, 206 // 101~110
};
int check_table(int low,int high, int num)
{
int mid;
if(num<arr[high-1]||num>arr[0]) return -1;//排除范围外的参数
while(high-low>1)
{
mid=(low+high)/2;//确定中间值
if(num<arr[mid])
low=mid;
else if(num>arr[mid])
high=mid;
else if (num==arr[mid])
return mid;
}
if(num>arr[1]) return 0;
return mid;
}
int main()
{
int i;
while(1)
{
printf("input number\n");
scanf("%d",&i);
printf("%d\n",check_table(0,140,i));
}
return 0;
}
09-06
3360
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-16
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交