fork download
  1.  
  2. #include <bits/stdc++.h>
  3. #define MAXN 200010
  4. #include <boost/multiprecision/cpp_int.hpp>
  5. using boost::multiprecision::cpp_int;
  6.  
  7.  
  8. using namespace std;
  9.  
  10.  
  11. bool sorthus (char i,char j){return (i>j);}
  12.  
  13. int main(){
  14. string cis,cis2,cis3;
  15. char temp;
  16. cin>>cis;
  17. cis3=cis;
  18. sort(cis3.begin(),cis3.end());
  19. long long cnt=0;
  20. for(long long i=0;i<cis3.size();i++)
  21. {
  22. if(cis3[i]=='0')cnt++;
  23. }
  24.  
  25.  
  26. if(cis3[0]=='-')
  27. {
  28. if(cis3[1]=='0'){
  29. swap(cis3[1],cis3[1+cnt]);
  30. }
  31.  
  32. }
  33. else {
  34. if(cis3[0]=='0')
  35. {
  36. swap(cis3[0],cis3[0+cnt]);
  37.  
  38. }
  39.  
  40.  
  41. }
  42.  
  43.  
  44. cis2=cis3;
  45. if(cis[0]=='-')
  46. {
  47. sort(cis2.begin()+1,cis2.end(),sorthus);
  48.  
  49.  
  50. }
  51. else {
  52. sort(cis2.begin(),cis2.end(),sorthus);
  53. }
  54. cpp_int cis22=stoi(cis2);
  55. cpp_int cis33=stoi(cis3);
  56. if(cis22<0)cout<<cis33-cis22<<endl;
  57. else cout<<cis22-cis33<<endl;
  58.  
  59.  
  60.  
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0s 16120KB
stdin
418
stdout
693