map<key_type,value_type> m;
map功能:自动建立key -> value的对应。key 和 value可以是任意类型
map的详细使用
#include <iostream>
#include <map>
#include <map>
using namespace std;
map <int ,int > t;
int main()
{
int n,Q,m;
cin>>n;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
t[x]=i;
//有x个球的位置为i
}
cin>>Q;
for(int i=1;i<=Q;i++)
{
cin>>m;
cout<<t[m]<<endl;
//有m个球的位置为t[m]
}
return 0;
}
提高一点效率可以用unordered_map
unordered_map