水题一道, 只是网上 流传 只有异或的方法, 觉得应该用更具有推广价值的代码。
#include<cstdio>
#include<set>
using namespace std;
set<int>t;
int main()
{
int n,i,temp;
while(scanf("%d",&n),n!=0)
{
t.clear();
for(i=0;i<n;i++)
{
scanf("%d",&temp);
if(t.count(temp)) t.erase(temp);
else t.insert(temp);
}
printf("%d\n",*t.begin());
}
}
本文介绍了一种使用C++标准库set来解决数组中重复元素问题的方法,相较于常见的异或解决方案,此方法更具通用性。通过遍历输入的整数并利用set的数据结构特性,可以高效地找出唯一出现的数字。
446

被折叠的 条评论
为什么被折叠?



