Advertisement
999ms

Best of tourist.

Mar 3rd, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.   int a,b;
  5.   string x,y;
  6.   cin>>a>>b;
  7.   x = to_string(abs(a));
  8.   y = to_string(abs(b));
  9.   if(a>0)
  10.     sort(x.begin(),x.end(),greater<>());
  11.   else
  12.     sort(x.begin(),x.end());
  13.   if(b>0)
  14.     sort(y.begin(),y.end());
  15.   else
  16.     sort(y.begin(),y.end(),greater<>());
  17.   for(int i=0;i<y.length();i++){
  18.     if(y[i]!='0'){
  19.       swap(y[i],y[0]);
  20.       break;
  21.     }
  22.   }
  23.   for(int i=0;i<x.length();i++){
  24.     if(x[i]!='0'){
  25.       swap(x[i],x[0]);
  26.       break;
  27.     }
  28.   }
  29.   if(a!=0) a /= abs(a);
  30.   if(b!=0) b /= abs(b);
  31.   a *= stoi(x);
  32.   b *= stoi(y);
  33.   cout<<a-b<<endl;
  34.   return 0;  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement