正好用到set的特性,如果已经存在,删除掉。
// Problem#: 2005
// Submission#: 3177025
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<set>
using namespace std;
int main() {
int test;
while (cin >> test) {
int temp;
set<int> mySet;
while (test--) {
cin >> temp;
if (mySet.count(temp))
mySet.erase(temp);
else
mySet.insert(temp);
}
cout << *mySet.begin() << endl;
}
}
本文介绍了一个使用C++编程语言中的set容器来处理输入数据并仅保留唯一值的算法示例。该程序通过读取整数,并利用set的特性自动去除重复项,最后输出处理后的首个元素。

816

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



