-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEliminate_Unique_Numbers.cpp
67 lines (53 loc) · 1.27 KB
/
Eliminate_Unique_Numbers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// There are some Special Numbers between 0 to 10^N.
// A number is called special, if all the digits in that number should be different.
// i.e., No two digits are same in that number.
// You are given an integer N,
// Your task is to find the count of special numbers (X) between 0<= X < 10^N.
// NOTE: Leading 0's are allowed.
// Input Format:
// -------------
// An integer N
// Output Format:
// --------------
// Print an integer, Count of special numbers.
// Sample Input-1:
// ---------------
// 1
// Sample Output-1:
// ----------------
// 10
// Sample Input-1:
// ---------------
// 2
// Sample Output-1:
// ----------------
// 91
// Explanation:
// --------------
// Special Number between 0<= X < 10^2.
// Exclude 11, 22, 33, 44, 55, 66, 77, 88, 99, => count is 9
// Total Count is 100=> Special Numbers count is 100-9 = 91.
#include<bits/stdc++.h>
using namespace std;
int c=0;
void solve(string &s,int n,string &x){
if(x.size()==n){
return;
}
for(int i=0;i<s.size();i++){
if(x.size()==0 || (x.find(s[i])==-1 && x[0]!='0')){
x=x+s[i];
c++;
solve(s,n,x);
x.pop_back();
}
}
}
int main(){
int n;
cin>>n;
string s="0123456789";
string x="";
solve(s,n,x);
cout<<c;
}