用map过的满分
查看原帖
用map过的满分
521342
StarryPilgrim楼主2021/10/13 16:10
#include<iostream>
#include<map>
using namespace std;
int n, m, temp, i, x = -1;
map<int, int>::iterator iter;
map<int, int> num;
main()
{
	cin >> n >> m;
	for (i = 0; i < n; i++)
	{
		cin >> temp;
		if(temp!=x)
			num.insert(pair<int, int>(temp, i));
			x = temp;
	}
	for (i = 0; i < m; i++)
	{
		cin >> temp;
		iter = num.find(temp);
		if (iter != num.end())
			cout << iter->second +1<< " ";
		else
			cout << "-1 " ;
	}
}

2021/10/13 16:10
加载中...