1041. Be Unique (20)

考察查询表

#include<iostream>
#include<vector>

typedef struct lottery
{
	int cnt;
	int index;
	lottery(int _cnt = 0, int _index = 0):cnt(_cnt),index(_index){}
}Lottery;
#define MAX 10000
int main()
{
	int N;
	while( scanf("%d", &N) != EOF )
	{
		std::vector<Lottery> lotVec(MAX+1);
		for(int i = 0; i < N; ++i)
		{
			int a;
			scanf("%d", &a);
			lotVec[a].cnt++;
			lotVec[a].index = i;
		}

		int ret = false;//none
		int minIdx = N;
		int flag;
		for(int i = 0; i < (int)lotVec.size(); ++i)
		{
			if(lotVec[i].cnt == 1)
			{
				if(lotVec[i].index < minIdx)
				{
					minIdx = lotVec[i].index;
					flag = i;
					ret = true;
				}
			}
		}
		//output
		if(false == ret)
			printf("None\n");
		else
			printf("%d\n", flag);
	}
	return 0;
}


 

你可能感兴趣的:(pat,ZJU)