文本
2025-07-19 11:02:39
发布于:上海
1阅读
0回复
0点赞
include<bits/stdc++.h>
using namespace std;
int main()
{
string a,b;
int T;
cin>>a;
cin>>T;
vector<int>c;
stringstream str(a);
while(getline(str,b,','))
{
c.push_back(stoi(b));
}
int s=c.size();
int L=0,R=s-1,m;
bool flag=false;
while(L<=R)
{
m=L+(R-L)/2;
if(c[m]T)
{
flag=true;
cout<<m;
break;
}
else if(c[m]<T)
{
L=m+1;
}
else
{
R=m-1;
}
}
if(flagfalse)cout<<"-1";
}
这里空空如也
有帮助,赞一个