Advertisement
erfanul007

UVa 1209

Dec 8th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string str,temp,ans;
  8. while(cin>>str){
  9. int i=0,cnt,cn,j,mn,tmn,mx;
  10. int ln=str.size();
  11. while(i<10){
  12. i++;
  13. prev_permutation(str.begin(),str.end());
  14. }
  15. i=0;
  16. mx=0;
  17. while(i<21){
  18. i++;
  19. mn=256;
  20. for(j=1;j<ln;j++){
  21. tmn=abs(str[j]-str[j-1]);
  22. if(tmn<mn)
  23. mn=tmn;
  24. }
  25. if(mn>mx){
  26. ans=str;
  27. mx=mn;
  28. }
  29. next_permutation(str.begin(),str.end());
  30. }
  31. cout<<ans<<mx<<endl;
  32. str.clear();
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement