Created
February 14, 2019 13:27
-
-
Save lapla-cogito/6d73701f6164f196002fa83b87c70475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
vector<int> digits(long long n){ | |
vector<int>res; | |
while(n){ | |
res.push_back(n%10); | |
n/=10; | |
} | |
sort(res.begin(),res.end()); | |
return res; | |
} | |
int main(){ | |
for(long long ii=100000;ii<=999999;++ii){ | |
long long ma=0,mi=0; | |
vector<int>mon=digits(ii); | |
for(int i=1,j=0;i<100000,j<6;i*=10,++j){ | |
ma+=i*mon[j]; | |
} | |
for(int i=100000,j=0;i>0,j<6;i/=10,++j){ | |
mi+=i*mon[j]; | |
} | |
if(ma-mi==ii){cout<<ii<<endl;} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment