Advertisement
amine99

Untitled

May 23rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  4. #define ALL(x) x.begin(),x.end()
  5. #define SZ(x) x.size()
  6. #define PB push_back
  7. #define MP make_pair
  8. #define F first
  9. #define S second
  10. typedef long long LL;
  11. typedef vector<int> VI;
  12. typedef pair<int,int> PI;
  13.  
  14. string a,b;
  15. int ans;
  16.  
  17. int main() {
  18.    io
  19.    cin >> a >> b;
  20.    sort(ALL(a));
  21.    int x = stoi(b);
  22.    int y = stoi(a);
  23.    if(y > x || SZ(a) > SZ(b))
  24.       return 0*puts("-1");
  25.    do {
  26.       y = stoi(a);
  27.       if(y <= x)
  28.          ans = max(ans,y);
  29.    } while(next_permutation(ALL(a)));
  30.    cout << ans;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement