题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1?tpId=37&tags=&title=&difficulty=0&judgeStatus=0&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D2%26tpId%3D37%26type%3D37
/* 思路:利用set容器来去重 1. 利用string 获得输入的字符串 2. 利用 reverse 翻转字符串 3. 创建 set<char> 容器 4. 创建结果字符串 res 5. 遍历字符串,同时检查 遍历到的字符是否在set容器中, 当当前字符不在set容器中时, 把当前字符用 append 函数加到res字符串中,同时把字符 insert 到 set 容器中 当当前字符在set容器中时,跳过 6. 打印res字符串 */ #include <algorithm> #include <iostream> #include <set> #include <unordered_set> using namespace std; int main() { string str, res; cin >> str; reverse(str.begin(), str.end()); set<char> mySet; for(auto c : str){ if(mySet.count(c) == 0){ res.append(1,c); mySet.insert(c); } } cout << res << endl; return 0; } // 64 位输出请用 printf("%lld")