Beautiful Year

迈不过友情╰ 2022-09-26 02:35 235阅读 0赞

Beautiful Year

Time Limit: 1000MS Memory Limit: 65536KB

Problem Description

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.
Given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.

Input

There are multiple test cases.
Each test case contains a single line contains integer y (1000 ≤ y ≤ 9000) — the year number.

Output

For each test case:
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.

Example Input

  1. 1987
  2. 2013

Example Output

  1. 2013
  2. 2014

Hint

Author

qinchuan

  1. #include<stdio.h>
  2. int main()
  3. {
  4. int n,m,k,i,j,a,b,c,d;
  5. while(scanf("%d",&n)!=EOF)
  6. {
  7. for(i=n+1;;i++)
  8. {
  9. a=i%10;
  10. b=(i/10)%10;
  11. c=(i/100)%10;
  12. d=(i/1000)%10;
  13. if(a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d)
  14. {
  15. printf("%d\n",i);
  16. break;
  17. }
  18. }
  19. }
  20. }

发表评论

表情:
评论列表 (有 0 条评论,235人围观)

还没有评论,来说两句吧...

相关阅读

    相关 New Year, New Me

    新的一年,新的开始 2017年,是我的毕业年,也是我开始参加工作的一年,这一年,很忙碌,很充实,却也很累,但也在一一实现着17年的计划,直到今日,十之八九得到了一个圆满的

    相关 Beautiful Soup

    1. Beautiful Soup的简介 Beautiful Soup 是用Python写的一个HTML/XML的解析器,它可以很好的处理不规范标记并生成剖析树(pars...