题解 | #提取不重复的整数#C++
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
用集合记录
用取余开路
用除等于循环
#include<iostream>
#include<set>
using namespace std;
int main() {
int n;
cin >> n;
set<int> set1;
int ans = 0;
while(n > 0) {
int temp = n % 10;
if (set1.count(temp) == 0) {
ans = ans * 10 + temp;
set1.insert(temp);
}
n /= 10;
}
cout << ans << endl;
return 0;
}
查看11道真题和解析