贪心去做
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, tmp;
vector<int> cnt(10);
vector<int> s;
vector<int> vis(10);
cin >> n;
tmp = n;
while(tmp > 0) {
cnt[tmp%10]++;
s.push_back(tmp%10);
tmp /= 10;
}
reverse(s.begin(), s.end());
stack<int> st;
for (int i = 0; i < s.size(); ++i) {
//cout << s[i] << endl;
cnt[s[i]]--;
if (st.empty()) {
st.push(s[i]);
vis[s[i]] = 1;
} else {
while(!st.empty() && st.top() < s[i] && cnt[st.top()] && !vis[s[i]]) {
vis[st.top()] = 0;
st.pop();
}
if (!vis[s[i]]) st.push(s[i]), vis[s[i]] = 1;
}
}
ll ans = 0, T = 1;
while (!st.empty()) {
ll x = st.top();st.pop();
ans += x*T;
T *= 10;
}
cout << ans << endl;
return 0;
}