#include <stdio.h>
#include<map>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
map<long long,int> m;
for(int i =0;i<n;i++){
long long x;
scanf("%lld",&x);
m[x]++;
}
map<long long,int>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
if(it->second==1){
printf("%lld\n",it->first);
break;}
}
}
return 0;
}
注意
map标准对象的运用:
map遍历:
for(map<int, string>::iterator it=map1.begin(); it!=map1.end(); it++)
{
cout << it->first << ":"<< it->second << endl;
}
查找
string value1 = map1[2];
if(value1.empty())
{cout << "not found"<< endl;}
//方法2
map<int, string>::iterator it = map1.find(2);
if(it == map1.end())
{cout << "not found"<< endl;}
else {cout << it->first << ":"<< it->second << endl;}