fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5.  
  6. void solve() {
  7. string s;
  8. cin >> s ;
  9. vector<int> freq(10,0);
  10. for(int i=0;i<10;i++)
  11. freq[s[i]-'0']++;
  12. string ans;
  13. for(int i=0;i<10;i++){
  14. for(int j=10-i-1;j<=9;j++){
  15. if(freq[j]>0){
  16. ans+=j+'0';
  17. freq[j]--;
  18. break;
  19. }
  20. }
  21. }
  22. cout << ans << '\n';
  23. }
  24.  
  25. int main(){
  26. ios::sync_with_stdio(false);
  27. cin.tie(nullptr);
  28.  
  29. int t;
  30. cin >> t;
  31. while (t--) solve();
  32.  
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 5292KB
stdin
4
9999999999
9988776655
9988776650
9899999999
stdout
9999999999
9876556789
9876567890
9899999999