本质上题意就是从右往左,每个数字只能出现一次,
随便使用一种方法管理每个数字出现的次数即可,这里使用map
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5 + 5; int __t = 1, n; void solve() { cin >> n; map<int, int> mp; while (n) { int x = n % 10; if (mp[x] == 0) { mp[x] = 1; cout << x; } n /= 10; } cout << "\n"; return; } int32_t main() { #ifdef ONLINE_JUDGE ios::sync_with_stdio(false); cin.tie(0); #endif // cin >> __t; while (__t--) solve(); return 0; }