Advertisement
999ms

Untitled

Mar 3rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 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.   if(a!=0) a /= abs(a);
  24.   if(b!=0) b /= abs(b);
  25.   a *= stoi(x);
  26.   b *= stoi(y);
  27.   cout<<a-b<<endl;
  28.   return 0;  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement