题解
2025-07-19 14:22:42
发布于:上海
7阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a,b;
int T;
cin>>a;
cin>>T;
vector<int>n;
stringstream str(a);
while(getline(str,b,','))
{
n.push_back(stoi(b));
}
int L=0,R=n.size()-1,M;
bool f=false;
while(L<=R)
{
M=L+(R-L)/2;
if(n[M]==T)
{
f=true;
cout<<M;
break;
}
else if(n[M]<T)L=M+1;
else R=M-1;
}
if(f==false)
{
cout<<"-1";
}
return 0;
}
这里空空如也
有帮助,赞一个