forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path271A - Beautiful Year.cpp
67 lines (42 loc) · 1.08 KB
/
271A - Beautiful Year.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
/*
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.
Output
Print a single integer — the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
inputCopy
1987
outputCopy
2013
inputCopy
2013
outputCopy
2014
*/
#include<bits/stdc++.h>
using namespace std;
bool isUnique(int y){
set<int> s;
int cnt=0;
while(y){
int rem=y%10;
y/=10;
s.insert(rem);
cnt++;
}
return s.size()==cnt;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int y;
cin>>y;
while(1){
y++;
if(isUnique(y)) break;
}
cout<<y;
return 0;
}