Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set<int> build(int n)
- {
- set<int> ans;
- int len = log(n)/log(10) + 1, i, j;
- for(i = 1;i<=len;i++)
- {
- for(j = 1;j<=i;j++)
- {
- for(char k = '1';k<='9';k++)
- {
- string s(j,k);
- for(char l = '0';l<='9';l++)
- {
- string s1(i - j, l);
- string num = s + s1;
- sort(begin(num),end(num));
- do{
- ans.insert(stoi(num));
- }
- while(next_permutation(begin(num),end(num)));
- }
- }
- }
- }
- return ans;
- }
- int countWeirdNumbers(int n) {
- set<int> x = build(n);
- vector<int> ans;
- for(auto i:x)
- ans.push_back(i);
- int index = lower_bound(begin(ans),end(ans), n) - ans.begin();
- if(ans[index] > n)
- index--;
- return index + 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement