Advertisement
trafik

Untitled

Sep 25th, 2022
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define len(v) (int)v.size()
  5. #define all(v) v.begin(), v.end()
  6. #define rall(v) v.rbegin(), v.rend()
  7. #define pii pair<int, int>
  8. #define vi vector<int>
  9. #define vii vector<vector<int>>
  10. #define vpii vector<pair<int, int>>
  11. #define ull unsigned long long
  12. //#define int long long
  13. const int N = 2e5 + 5;
  14. const int C = 20;
  15. const int logn = 20;
  16. const ll inf = 1e12;
  17. const int mod = 1e9 + 7;
  18. const int M = 1e9;
  19. const ull M2 = 998244353;
  20. const ld eps = 1e-6;
  21. using namespace std;
  22.  
  23. template<class T>
  24. istream &operator>>(istream &in, vector<T> &a) {
  25.     for (auto &i : a)
  26.         in >> i;
  27.     return in;
  28. }
  29.  
  30. template<class T>
  31. ostream &operator<<(ostream &out, vector<T> &a) {
  32.     for (auto &i : a)
  33.         out << i;
  34.     return out;
  35. }
  36.  
  37. ld f(ld x0, vector<ld>& x, vector<ld>& t) {
  38.     ld ans = 1e17 + 1.0;
  39.     for (int i = 0; i < len(x); ++i) {
  40.         ans = min(ans, t[i] + abs(x[i] - x0));
  41.     }
  42.     return ans;
  43. }
  44.  
  45. void solve() {
  46.     string s; cin >> s;
  47.     int n = len(s);
  48.     vector<int> d1, d2;
  49.     int i = -1;
  50.     while (i + 1 < n) {
  51.         int mini = i + 1;
  52.         for (int j = i + 1; j < n; ++j)
  53.             if ((s[j] - '0') < (s[mini] - '0'))
  54.                 mini = j;
  55.         d1.push_back(s[mini] - '0');
  56.         for (int j = i + 1; j < mini; ++j)
  57.             d2.push_back(min(s[j] - '0' + 1, 9));
  58.         i = mini;
  59.     }
  60.     for (auto c : d2)
  61.         d1.push_back(c);
  62.     sort(all(d1));
  63.     cout << d1;
  64.     cout << '\n';
  65. }
  66.  
  67. signed main() {
  68.     ios::sync_with_stdio(false);
  69.     cin.tie(nullptr);
  70.     cout.tie(nullptr);
  71.  
  72.     int T = 1;
  73.     cin >> T;
  74.     while (T--)
  75.         solve();
  76. }
  77.  
  78. /*
  79.      ▄▀▀▀▄
  80. ▄███▀░◐░░░▌
  81.     ▌░░░░░▐
  82.     ▐░░░░░▐
  83.     ▌░░░░░▐▄▄
  84.     ▌░░░░▄▀▒▒▀▀▀▀▄
  85.    ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
  86.    ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
  87.     ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
  88.       ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
  89.            ▌▌░▌▌
  90.            ▌▌░▌▌
  91.          ▄▄▌▌▄▌▌        */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement