首页 > 其他 > 详细

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

时间:2016-07-20 19:06:40      阅读:167      评论:0      收藏:0      [点我收藏+]

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

技术分享
#include <iostream>
#include <algorithm>
using namespace std;
bool chk(int x)
{
    int a[4];
    for (int i = 0; i < 4; i ++)
    {
        a[i] = x % 10;
        x /= 10;
    }
    sort(a, a + 4);
    for (int i = 1; i < 4; i ++)
        if (a[i] == a[i-1])
            return false;
    return true;
}
int get(const int & x)
{
    for(int i = x+1; ; i ++)
        if (chk(i))
            return i;
}
int main()
{
    int n;
    cin >> n;
    cout << get(n);
    return 0;
}
C++

 

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

原文:http://www.cnblogs.com/moonlightpoet/p/5689146.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!