80分了,就差#7一个测试点死活过不去,求教求教!!!

P1618 三连击(升级版)

77Glorious @ 2023-10-28 22:37:49

#include <bits/stdc++.h>
using namespace std;
int a[10];

void pd(int x) {

    int tmp;
    while (x != 0) {
        tmp = x % 10; //123->3
        x = x / 10; //123->12
        a[tmp]++; //判断每个数位是否占位为1
    }
}

int zw[2];//占位数组
int A, B, C;
int i ;

int main() {
    cin >> A >> B >> C;
    if (A == 0) {
        cout << "No!!!";
        return 0;
    }
    for (i = 123; i <= 333; i++) {
        pd(i);
        pd(i / A * B);
        pd(i / A * C);
        if (a[1] == 1 && a[2] == 1 && a[3] == 1 && a[4] == 1 && a[5] == 1 && a[6] == 1 && a[7] == 1 && a[8] == 1 && a[9] == 1
                && i / A * B < 999 && i / A * C <= 999) {
            cout << i << ' ' << i / A *B << ' ' << i / A *C << endl;
            zw[1] = i;
        }
        for (int j = 1; j <= 9; j++)
            a[j] = 0;
    }
    if (zw[1] == 0)
        cout << "No!!!";

    return 0;
}

by donaldqian @ 2023-10-28 22:46:19

不太清楚是不是要判断一下 i 是否是 A 的倍数? @Vanxia1266


by donaldqian @ 2023-10-28 22:48:35

还有 i 不一定必须小于 333

例如 345, 876, 912 这种说不定也可以


by 77Glorious @ 2023-10-28 22:57:08

感谢大佬提醒倍数判断!@donaldqian0712


|