StoneHaos

300

Nov 3rd, 2019
390
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //300
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. int main(void) {
  8.     freopen("input.txt", "r", stdin);
  9.     freopen("output.txt", "w", stdout);
  10.  
  11.     char a[11];
  12.     int b;
  13.     scanf("%s%d", a, &b);
  14.     int len = strlen(a);
  15.     sort(a, a + len);
  16.     reverse(a, a + len);
  17.     for (; atoi(a) > b; prev_permutation(a, a + len));
  18.     printf("%s\n", a);
  19.     return 0;
  20. }
RAW Paste Data