本题链接: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;
}
水题,不解释
本文发布于:2024-01-28 13:45:35,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17064207397834.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |