简单呢
#include <iostream> #include <unordered_set> using namespace std; int main() { string str; cin >> str; unordered_set<char> s; for (int i = str.size()-1; i != -1; i--) { if (s.find(str[i]) == s.end()) { cout << str[i]; s.emplace(str[i]); } } }
#include <iostream> #include <unordered_set> using namespace std; int main() { string str; cin >> str; unordered_set<char> s; for (int i = str.size()-1; i != -1; i--) { if (s.find(str[i]) == s.end()) { cout << str[i]; s.emplace(str[i]); } } }