Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int a,b;
- string x,y;
- cin>>a>>b;
- x = to_string(abs(a));
- y = to_string(abs(b));
- if(a>0)
- sort(x.begin(),x.end(),greater<>());
- else
- sort(x.begin(),x.end());
- if(b>0)
- sort(y.begin(),y.end());
- else
- sort(y.begin(),y.end(),greater<>());
- for(int i=0;i<y.length();i++){
- if(y[i]!='0'){
- swap(y[i],y[0]);
- break;
- }
- }
- for(int i=0;i<x.length();i++){
- if(x[i]!='0'){
- swap(x[i],x[0]);
- break;
- }
- }
- if(a!=0) a /= abs(a);
- if(b!=0) b /= abs(b);
- a *= stoi(x);
- b *= stoi(y);
- cout<<a-b<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement