蓝桥杯 基础练习 查找整数
题目:http://lx.lanqiao.cn/problem.page?gpid=T9
参考:https://blog.csdn.net/zhouzhenhe2008/article/details/40595491
https://blog.csdn.net/wjh2622075127/article/details/79456849
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n,temp; 6 cin>>n; 7 vector<int> ve; 8 for (int i=0;i<n;i++) 9 { 10 cin>>temp; 11 ve.push_back(temp); 12 } 13 int tofind; 14 cin>>tofind; 15 vector<int>::iterator it=find(ve.begin(),ve.end(),tofind); 16 if (it==ve.end()) 17 { 18 cout<<"-1"<<endl; 19 } 20 else 21 { 22 int pos=distance(ve.begin(),it); 23 cout<<pos+1<<endl; 24 } 25 26 return 0; 27 }