1041 Be Unique (20分)

map裸题吧,当然由于数字大小在 ([1,10^4]) ,所以开数组记录也是可以的。

const int N=1e5+10;
int a[N];
map<int,int> mp;
int n;

int main()
{
    cin>>n;

    for(int i=0;i<n;i++) cin>>a[i],mp[a[i]]++;

    int res=-1;
    for(int i=0;i<n;i++)
        if(mp[a[i]] == 1)
        {
            res=a[i];
            break;
        }

    if(res == -1) puts("None");
    else cout<<res<<endl;

    //system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/fxh0707/p/14355152.html