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. VSX-1 概述

    博客搁置了一段时间,一直想写,无从下手,正好最近在做VS2010扩展方面的项目,所以写VSX系列文章以记之. 背景 现有工作是做金融行业,主要项目是一套银行综合前端系统,也就是银行平时用的最多的一个系 ...

  2. Python 3基础教程12-常见的错误

    本文来介绍几种常见的错误,任何人在刚开始接触一个新的语言,即使照着代码抄写,也可能会犯错误,这里我们就介绍几种常见的错误,看看你是否遇到过. 1. NameError: name 'xxx' is n ...

  3. unity灯光Lightmapping、LightProbes

    1.为什么要用Lightmapping? 简单来说就是实时灯光计算十分耗时,随着光源越多,计算耗时会倍增.使用Lightmap模拟灯光带来的效果,便不用去计算灯光,会带来性能上的大大提升. 当然一个复 ...

  4. Python namedtuple(命名元组)使用实例

    Python namedtuple(命名元组)使用实例 #!/usr/bin/python3 import collections MyTupleClass = collections.namedtu ...

  5. 用Linkedhashmap的LRU特性及SoftReference软引用构建二级缓存

    LRU: least recently used(近期最少使用算法).LinkedHashMap构造函数可以指定其迭代顺序:LinkedHashMap(int initialCapacity, flo ...

  6. composer 库无法提交git

    composer require firebase/php-jwt 安装了该库,想提交到版本库,无论如何也提交不上去,.ignore中也没忽略,网上寻找答案,说有个.git文件夹需要删除 PHPSTO ...

  7. springmvc中RedirectAttributes、SessionFlashMapManager的作用

    RedirectAttributes 在重定向的时候可以传参,不能跨站传参,因为参数是保存在服务器端Session中SessionFlashMapManager 是RedirectAttributes ...

  8. [SP10707]COT2 - Count on a tree II

    题目大意:有一棵$n$个节点的树,第$i$个点有一个颜色$C_i$,$m$组询问,每次问$x->y$的路径上有多少种颜色 题解:树上莫队,把树按欧拉序展开成一条链,令第$i$个节点第一次出现在序 ...

  9. [codeforces] 578C Weakness and Poorness || 三分

    原题 题目定义了两个变量: poorness表示一个区间内和的绝对值. weakness表示一个所有区间最大的poornesss 题目要求你求一个x使得 a1 − x, a2 − x, ..., an ...

  10. 洛谷 P2375 [NOI2014]动物园 解题报告

    P2375 [NOI2014]动物园 题目描述 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅,只会卖萌向游客要吃的.为了整治动物园的不良风气,让动物们凭自己的真才实学向游客要吃的,园长决定 ...