Beautiful Year
一、 Beautiful Year
本题链接:Beautiful Year
题目:
A. Beautiful Year
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Examples
input
1987
output
2013
input
2013
output
2014
本博客给出本题截图:
题意:输入一个数,找到比这个数大的数中,满足每个位置上的数都不同的数中的最小的数
AC代码
#include <iostream>
#include <cstring>
using namespace std;
const int N = 10;
int a[N];
int main()
{
int n;
cin >> n;
for (int i = n + 1; ; i ++ )
{
memset(a, 0, sizeof a);
int m = i;
while (m)
{
int t = m % 10;
a[t] ++;
m /= 10;
}
bool flag = true;
for (int j = 0; j < 10; j ++ )
if (a[j] == 0) continue;
else if (a[j] != 1)
{
flag = false;
break;
}
if(flag)
{
cout << i << endl;
break;
}
}
return 0;
}
- 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
总结
水题,不解释
文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。
原文链接:chen-ac.blog.csdn.net/article/details/117457862
- 点赞
- 收藏
- 关注作者
评论(0)