-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcode_1.cpp
More file actions
45 lines (38 loc) · 850 Bytes
/
code_1.cpp
File metadata and controls
45 lines (38 loc) · 850 Bytes
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
//
// code_1.cpp
// Algorithm
//
// Created by Mohd Shoaib Rayeen on 23/11/18.
// Copyright © 2018 Shoaib Rayeen. All rights reserved.
//
#include <iostream>
#include <unordered_set>
using namespace std;
int repeated_digit(int n) {
unordered_set<int> s;
while(n != 0) {
int d = n % 10;
if(s.find(d) != s.end()) {
return 0;
}
s.insert(d);
n = n / 10;
}
return 1;
}
int getUnrepeatedDigitsNumber(int L,int R) {
int answer = 0;
for(int i = L; i <= R; ++i) {
answer = answer + repeated_digit(i);
}
return answer ;
}
int main() {
int L , R;
cout << "\nEnter L\t:\t";
cin >> L;
cout << "\nEnter R\t:\t";
cin >> R;
cout << "\nUnrepeated Digits-Numbers Count\t:\t" << getUnrepeatedDigitsNumber(L , R) << "\n";
return 0;
}