STL二分查找

#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

int main()
{
    double num[10]={1,2,3,4,4,5,5,5,6,7},a;
    while(cin>>a && a)
    {
        cout<<upper_bound(num,num+10,a)-num<<endl;  //查比a来的大的第一个数的下标
        cout<<lower_bound(num,num+10,a)-num<<endl;  //查比a大的数或者等于a的第一个数的下标
        cout<<endl;
    }
    return 0;
}
全部评论

相关推荐

05-12 16:04
已编辑
江西财经大学 Java
点赞 评论 收藏
分享
06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务