Beautiful Year

举报
辰chen 发表于 2022/06/16 23:30:49 2022/06/16
【摘要】 文章目录 一、 Beautiful Year总结 一、 Beautiful Year 本题链接:Beautiful Year 题目: A. Beautiful Year time ...


一、 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

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。