题解 | #提取不重复的整数#
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
首先,对输入的整形数字进行划分,每次取出最低位数字,这可以通过/10操作实现。而后,利用unordered_set容器进行去重。需要注意的是,由于unordered_set容器是无序的,因此输出数字的时候不能通过迭代器遍历容器来输出,而应该在每次判断之后直接输出。
#include <unordered_set>
using namespace std;
int main() {
int N;
cin >> N;
float judge = N / 10;
unordered_set<int> res;
while (judge > 0.1) {
int temp = N / 10;
judge = N / 10;
int num = N - temp * 10;
N = temp;
if (res.find(num) == res.end()) {
res.insert(num);
cout<< num;
}
}
return 0;
}