UVa 11991 Easy Problem from Rujia Liu? / STL-MAP

输入n个数 然后m对k v求第k个v的下标 没有输出0

用map 先预处理好 直接输出a[v][k]

容器里面套容器 第一次遇到

#include <map>
#include <cstdio>
#include <vector>
using namespace std;
map <int, vector <int> > a;
int main()
{
	int n, m;
	int u, v;
	int i, j;
	while(scanf("%d %d",&n,&m) !=EOF)
	{
		a.clear();
		for(i = 0; i < n; i++)
		{
			scanf("%d", &j);
			if(!a.count(j))
				a[j] = vector <int>();
			a[j].push_back(i+1);
		}
		while(m--)
		{
			scanf("%d %d", &u, &v);
			if(!a.count(v) || a[v].size() < u)
				printf("0\n");
			else
				printf("%d\n", a[v][u-1]);
		}
	}	
	return 0;
}


 

UVa 11991 Easy Problem from Rujia Liu? / STL-MAP

上一篇:Linux命令详解之file


下一篇:Struts2异常----- According to TLD or attribute directive in tag file, attribute test