Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<string>
- using namespace std;
- int main()
- {
- string str,temp,ans;
- while(cin>>str){
- int i=0,cnt,cn,j,mn,tmn,mx;
- int ln=str.size();
- while(i<10){
- i++;
- prev_permutation(str.begin(),str.end());
- }
- i=0;
- mx=0;
- while(i<21){
- i++;
- mn=256;
- for(j=1;j<ln;j++){
- tmn=abs(str[j]-str[j-1]);
- if(tmn<mn)
- mn=tmn;
- }
- if(mn>mx){
- ans=str;
- mx=mn;
- }
- next_permutation(str.begin(),str.end());
- }
- cout<<ans<<mx<<endl;
- str.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement