cpp
复制代码
int main(void)
{
int i = 0;
int len = 0;
char c = '\0';
int data[100];
int left = 0;
int right = 0;
int middle = 0;
int tag = 0;
int index = 0;
while(scanf("%d",&data[i]) == 1)
{
i++;
len++;
c = getchar();
if(c == '\n')
break;
}
scanf("%d",&tag);
// for(i=0; i<len; i++)
// {
// printf("%d ",data[i]);
// }
// printf("%d \n",tag);
right = len-1;
middle = (left+right)/2;
while(left<right)
{
if(data[middle]>tag)
{
right = middle-1;
}
else
{
left = middle+1;
}
if(left == right)
{
index = left+2;
break;
}
middle = (left+right)/2;
}
printf("%d",index);
}