UVA725 Division(暴力美学)

本题vjudge链接

  • 题意:给你一个数n,让你求出 a b c d e / f g h i j = n abcde / fghij = n abcde/fghij=n 的所有结果,a ~ j 的恰好是 0 ~ 9 的数
  • 暴力遍历分子就好了,然后检查分母是否合法就行了
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int M = 1e5;
int n;

bool check(int a, int b) {
    bool num[10] = {0};
    if (b < 10000) num[0] = true;
    while (a || b) {
        num[a % 10] = true;
        num[b % 10] = true;
        a /= 10, b /= 10;
    }
    int x = 0;
    for (auto i : num) if (i) x++;
    return x == 10;
}

bool check(int a) {
    bool num[10] = {0};
    if (a < 10000) num[0] = true;
    while (a) {
        num[a % 10] = true;
        a /= 10;
    }
    int x = 0;
    for (auto i : num) if (i) x++;
    return x == 5;
}

int main () {
#ifndef ONLINE_JUDGE
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#endif
    bool f = true;
    while (scanf("%d", &n), n) {
        if (f) f = false;
        else puts("");
        bool ok = true;
        for (int i = 11111; i < M; i++) {
            if (i % n == 0 && check(i) && check(i / n) && check(i, i / n)) {
                ok = false;
                printf("%05d / %05d = %d\n", i, i / n, n);
            }
        }
        if (ok) printf("There are no solutions for %d.\n", n);
    }
    return 0;
}

原地址

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值