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

题目链接: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++
原文地址:https://www.cnblogs.com/moonlightpoet/p/5689146.html