小米oj #2.找出单独出现的数字 map应用

题目链接https://code.mi.com/problem/list/view?id=2
描述

给出N个数字。其中仅有一个数字出现过一次,其他数字均出现过两次,找出这个出现且只出现过一次的数字。要求时间和空间复杂度最小。

输入

输入多个数字,每个数字以空格分开。数字数量 N < 20,输入数字的最大值小于 256.

输出

输出内容为只出现过唯一一次的数字

输入样例

10 10 11 12 12 11 16

输出样例

16

#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;

map<int,int> m;
map<int, int>::iterator it;
int main()
{
	int n;
	while (cin >> n){
		m[n]++;
	}
	for (it = m.begin(); it != m.end(); it++){ 

		if (it->second == 1)
			cout << it->first;

	}
	return 0;
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Mr_HCW/article/details/88625213
今日推荐