码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-07-20 19:07:36      阅读:145      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!