题解 | #找x#
找x
https://www.nowcoder.com/practice/069e2130430c41229ab25e47fa0949a6
#include <bits/stdc++.h> using namespace std; int main(){ int n,x,f; while(cin>>n){ map<int,int> mp;//输入的数各不相同,故可用映射 for(int i=0;i<n;i++){ cin>>x; mp[x] = i; } cin>>f; if(mp.find(f)!=mp.end()) cout<<mp[f]<<endl; else{ cout<<-1<<endl; } } return 0; }