题解 | 找x

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    while (cin>>n) {
        map<int,int>a;
        for(int i=0;i<n;i++){
            int y;cin>>y;
            a[y]=i+1;
        }
        int x;cin>>x;
        if(a[x]==0)cout<<-1<<endl;
        else cout<<a[x]-1<<endl;
    }
}

用map搜更快速

全部评论

相关推荐

点赞 评论 收藏
分享
牛客21331815...:像我一投就pass,根本不用焦虑泡池子
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务