题目: http://lx.lanqiao.cn/problem.page?gpid=T9
参考:
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,temp;
- cin>>n;
- vector<int> ve;
- for (int i=0;i<n;i++)
- {
- cin>>temp;
- ve.push_back(temp);
- }
- int tofind;
- cin>>tofind;
- vector<int>::iterator it=find(ve.begin(),ve.end(),tofind);
- if (it==ve.end())
- {
- cout<<"-1"<<endl;
- }
- else
- {
- int pos=distance(ve.begin(),it);
- cout<<pos+1<<endl;
- }
- return 0;
- }
来源: http://www.bubuko.com/infodetail-2972638.html