我是靠谱客的博主 笨笨金鱼,这篇文章主要介绍codeforces 271A Beautiful Year(暴力水题),现在分享给大家,希望可以做个参考。

A. Beautiful Year
点击打开题目
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
Input
复制代码
1
1987
Output
复制代码
1
2013
Input
复制代码
1
2013
Output
复制代码
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
68
69
70
71
72
73
74
75
76
77
78
2014 ╮(╯▽╰)╭ 被y<=9000,坑了,我这水平不能再水了,加油!!! 代码:
复制代码
#include <iostream>
using namespace std;
bool check(int n)
{
int i=0,a[4],j;
while(n)
{
a[i++]=n%10;
n/=10;
//cout<<a[i-1]<<endl;
}
for(i=0;i<4;i++)
{
for(j=i+1;j<4;j++)
{
if((a[i]==a[j]))
return false;
}
}
return true;
}
int main()
{
int i,n;
while(cin>>n)
{
for(i=n+1;;i++)
{
if(check(i))
{
cout<<i<<endl;
break;
}
}
}
return 0;
}


最后

以上就是笨笨金鱼最近收集整理的关于codeforces 271A Beautiful Year(暴力水题)的全部内容,更多相关codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部