题解 | #提取不重复的整数#
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_set>
using namespace std;
int main(){
int num = 0;
cin >> num;
string str = to_string(num);
reverse(str.begin(), str.end());
unordered_set<char> tmp;
int res = 0;
for(int i = 0; i < str.size(); i++){
if(tmp.count(str[i]) == 0){
res = res * 10 + (str[i] - '0');
}
tmp.insert(str[i]);
}
cout << res << endl;
return 0;
}
华为题库题解 文章被收录于专栏
牛客华为题库的题解