Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  f.cpp
Language: C/C++
Code:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long int a1,b1,mn=99999999999;
     string a,b,i;
     cin>>a>>b;
     sort(a.begin(),a.end());
     do{
        // cout<<a<<" ";
         if(a>b&&stoll(a)<mn)
         {
             mn=stoll(a);
             //exit(0);
         }
            
     }while(next_permutation(a.begin(),a.end()) );
     if(mn==99999999999)
     cout<<"-1";
     else
     cout<<mn;
     return 0;
}
     
Comments: