Codeforces Round #166 (Div. 2) A. Beautiful Year(水题)
2013-02-17 19:54
3299 查看
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
Output
Input
Output
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
1987
Output
2013
Input
2013
Output
2014
#include <iostream> #include <cstdio> using namespace std; int main() { int y; while(scanf("%d", &y) != EOF) { while(y++) { int tmp = y; int a = tmp % 10; tmp /= 10; int b = tmp % 10; tmp /= 10; int c = tmp % 10; tmp /= 10; int d = tmp % 10; if(a != b && a != c && a != d && b != c && b != d && c != d) { printf("%d\n", y); break; } } } return 0; }
相关文章推荐
- Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题
- Codeforces Round #375 (Div. 2)A. The New Year: Meeting Friends(水题)
- 【Codeforces Round 375 (Div 2) A】【水题】The New Year Meeting Friends
- Codeforces Beta Round #92 (Div. 2) / 124A The number of positions 【简单模拟】【水题】
- Codeforces Round #201 (Div. 2) ABC 水题3道
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) A. Gotta Catch Em' All!(水题)
- cf#8VC Venture Cup 2016 - Final Round (Div. 2 Edition) -A. Orchestra暴力水题
- 【Good Bye 2014A】【水题 dfs】New Year Transportation 可否传送到t点
- 【HDU5650 BestCoder Round 77 (div2) A】【水题】so easy 集合所有子集异或和的异或和
- Codeforces Round #395 (Div. 2) A. Taymyr is calling you(水题)
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution 水题
- Codeforces Round #371 (Div. 2) A. Meeting of Old Friends (水题)
- B. Pasha and String(Codeforces Round #297 (Div. 2) 水题)
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题
- Codeforces Round #353 (Div. 2) B. Restoring Painting 水题
- codeforces 97 div2 C.Replacement 水题
- 【Codeforces Round 331 (Div 2)B】【水题 贪心】Wilbur and Array 修改对p位置后的所有位置生效 最少修改次数使得数列变成b
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
- Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo(水题)