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.

Examples
input
1987
output
2013
input
2013
output
2014

【题意】:给你一个数。求大于该数且每个位数不相同。四位数。
【分析】:逆向思维,类似回文串,双重循环,一个指针遍历,另一个指针紧跟其后。两两一相等就return false了。
【代码】:
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
bool check(int n)
{
int i=,a[],j;
while(n)
{
a[i++]=n%;
n/=;
} for(int i=;i<;i++)
{
for(int j=i+;j<;j++)
{
if(a[i]==a[j])
return false;
}
}
return true;
}
int main()
{
int n;
while(cin>>n)
{
for(int i=n+; ;i++)
{
if(check(i))
{
cout<<i<<endl;
break;
}
}
}
return ;
}

类似回文串的判断

Codeforces Round #166 (Div. 2) A. Beautiful Year【暴力枚举/逆向思维/大于当前数且每个位数不同】的更多相关文章

  1. codeforces水题100道 第十三题 Codeforces Round #166 (Div. 2) A. Beautiful Year (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/271/A题意:给你一个四位数,求比这个数大的最小的满足四个位的数字不同的四位数.C++代码: #i ...

  2. Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力

    B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...

  3. 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

    题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...

  4. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  5. Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)

    题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...

  6. Codeforces Round #349 (Div. 1) B. World Tour 暴力最短路

    B. World Tour 题目连接: http://www.codeforces.com/contest/666/problem/B Description A famous sculptor Ci ...

  7. Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分

    D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...

  8. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  9. Codeforces Round #566 (Div. 2) C. Beautiful Lyrics

    链接: https://codeforces.com/contest/1182/problem/C 题意: You are given n words, each of which consists ...

随机推荐

  1. 以最省内存的方式把大图片加载到内存及获取Exif信息和获取屏幕高度和宽度的新方法

    我们在加载图片时经常会遇到内存溢出的问题,图片太大,我们加载图片时,一般都是用的如下一般方法(加载本地图片): /** * 不作处理,去加载图片的方法,碰到比较大的图片会内存溢出 */ private ...

  2. 《数据结构》C++代码 Splay

    Splay,伸展树.之所以先写这个课内并不怎么常用的数据结构,是因为本人非常喜欢Splay,我觉得这是非常有美感且灵活的一种平衡树.在此先声明,我的伸展树写法来源于CLJ大牛,基础好的同学可以去他的博 ...

  3. leetcode 【Rotate List 】python 实现

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...

  4. Jetty 安装、启动与项目部署

    Jetty是当下非常流行的一款轻量级Java Web服务器和Servlet容器实现,它由Eclipse基金会托管,完全免费而且开放源代码,因此所有人均可以从其官网下载最新源代码进行研究.由于其轻量.灵 ...

  5. mysql基础知识点整理

    数据库与数据表的创建.修改.删除 创建数据库: Create database 数据库名 删除数据库: drop database 数据库名 修改字符集为utf8并指定校对集(mysql默认字符集为l ...

  6. java jdbc与odbc数据库的连接mysql数据库

    1.jdbc连接数据库要添加mysql-connector-java-5.1.38-bin.jar库 2.odbc连接数据库要添加odbc数据源 3.测试代码 DBHelper.java代码jdbc连 ...

  7. 使用UltraEdit搭建自己的C/C++ IDE

    使用UltraEdit搭建自己的C/C++ IDE CodeBlocks的13.12版本啊,主要缺点是启动慢,而且在Windows上容易假死,写着写着就无响应了,然后死活活不过来.所以没办法,只好干脆 ...

  8. HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )

    空间异面直线的距离直接套模板. 求交点:求出两条直线的公共法向量,其中一条直线与法向量构成的平面 与 另一条直线 的交点即可.还是套模板o(╯□╰)o 1.不会有两条线平行的情况. 2.两条直线可能相 ...

  9. if else以及大于、小于、等于逻辑表达式

    大多数情况下,可以使用测试命令来对条件进行测试.比如可以比较字符串.判断文件是否存在及是否可读等,通常用"[]"来表示条件测试.注意这里的空格很重要.要确保方括号的空格. if . ...

  10. Java并发(1)- 聊聊Java内存模型

    引言 在计算机系统的发展过程中,由于CPU的运算速度和计算机存储速度之间巨大的差距.为了解决CPU的运算速度和计算机存储速度之间巨大的差距,设计人员在CPU和计算机存储之间加入了高速缓存来做为他们之间 ...