【USACO】Runround Numbers

用了一个蠢办法,反正过了。懒得弄了。
/*
ID :
LANG: C++11
TASK: runround
 */

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std;

char c[32] = {};
bool b[32] = {};
bool bR[10] = {};

inline bool test(int m){
    memset(c, 0, sizeof(c));
    memset(b, 0, sizeof(b));
    memset(bR, 0, sizeof(bR));
    sprintf(c, "%d", m);
    string s(c);
    int l = s.length();
    int count = 1;
    int p = s[0] - '0';
    b[0] = true;
    bR[s[0] - '0'] = true;
    if (p >= l)
        p = p % l;
    while (p != 0){
        if (b[p] == true || bR[s[p] - '0'] == true)
            return false;
        b[p] = true;
        bR[s[p] - '0'] = true;
        p = p + s[p] - '0';
        p %= l;
        count ++;
    }
    if (count < l)
        return false;
    return true;
}

int main()
{
    freopen("runround.in", "r", stdin);
    freopen("runround.out", "w", stdout);
    unsigned long M;
    cin >> M;
    int m = M + 1;
    while (!test(m)){
        m++;
    }
    cout << m << endl;

    return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值