-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPANDIGITALnumbers.cpp
64 lines (56 loc) · 1.07 KB
/
PANDIGITALnumbers.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
/*
* https://www.hackerearth.com/challenge/competitive/april-easy-17/algorithm/mancunian-and-pandigital-numbers-1/
* Program that printd the number of PANDIGITAL numbers in a range
*
* @coder_nigga
*
*/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int digits(int a){
int count = 0;
while(a){
a=a/10;
count++;
}
return count;
}
int pan(int n, int digits){
int a[12]={0};
int flag = 1;
int c;
while(n){
c=n%10;
n=n/10;
if(a[c]==0)
a[c]++;
else{
flag = 0;
break;
}
}
for(int i=1; i<=digits; i++){
if(a[i]!=1){
flag=0;
break;
}
}
return flag;
}
int main()
{
int t,l,r;
cin>>t;
while(t--){
cin>>l>>r;
int count = 0;
for(int i=l; i<=r; i++){
if(pan(i,digits(i))){
count++;
}
}
cout<<count<<endl;
}
return 0;
}