题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
#include <string> #include <iostream> #include <unordered_set> #include <algorithm> using namespace std; string Handle(string str); int main(){ string a; cin >> a; string b = Handle(a); cout << b << endl; return 0; } string Handle(string str){ unordered_set<char> st; string Rlt; reverse(str.begin(), str.end()); for (const char& p1 : str){ if (st.insert(p1).second){ Rlt.push_back(p1); } } return Rlt; }
利用set的特性检查字符是否已经存在,将不存在的字符添加上去。