题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
while (cin >> a) { // 注意 while 处理多个 case
set<int> s;
vector<int> v;
string str = to_string(a);
string str1;
for (int i = str.size() - 1; i >= 0; i--) {
// 强制转换的时候还要注意ascii码的问题
// '7'-'0' = 7,背后是55-48
int b = str[i] - '0';
if (s.find(b) == s.end()) {
v.push_back(b);
}
s.insert(b);
}
for (int i = 0; i < v.size(); i++) {
str1 += to_string(v[i]);
}
int res = stoi(str1);
cout << res;
}
return 0;
}