文章目录
一、 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; }
总结
水题,不解释