玄关求助

P1618 三连击(升级版)

jaspersgr114514 @ 2024-09-22 13:37:53

#include <bits/stdc++.h>
using namespace std;
bool check(int x, int y, int z)
{
    bool use[10];
    memset(use, false, sizeof(use));
    while (x)
    {
        if (use[x % 10] == true || x % 10 == 0)
            return false;
        else
        {
            use[x % 10] = true;
            x /= 10;
        }
    }
    while (y)
    {
        if (use[y % 10] == true || y % 10 == 0)
            return false;
        else
        {
            use[y % 10] = true;
            y /= 10;
        }
    }
    while (z)
    {
        if (use[z % 10] == true || z % 10 == 0)
            return false;
        else
        {
            use[z % 10] = true;
            z /= 10;
        }
    }
    return true;
}
int main()
{
    int a, b, c;
    bool flag = false;
    cin >> a >> b >> c;
    for (int i = 100; i <= 333; i++)
    {
        if (i % a != 0)
            continue;
        int x = i;
        int y = i / a * b;
        int z = i / a * c;
        if (x >= 1000 || y >= 1000 || z >= 1000)
            continue;
        if (check(x, y, z))
        {
            flag = true;
            cout << x << ' ' << y << ' ' << z << endl;
        }
    }
    if (flag == false)
    {
        cout << "No!!!";
    }
}


by guojiahong @ 2024-09-22 13:41:50

a==0


by guojiahong @ 2024-09-22 13:43:29

@jaspersgr114514


by jaspersgr114514 @ 2024-09-22 13:46:36

第几行? @guojiahong


by jaspersgr114514 @ 2024-09-22 13:47:54

i % a != 0 是为了保证后面不会出现除不尽的情况


by guojiahong @ 2024-09-22 13:48:44

if (i % a != 0),模 0 会 RE。


by guojiahong @ 2024-09-22 13:49:40

除以 0 也会 RE。


by guojiahong @ 2024-09-22 13:52:19

for循环前加一个if(a==0){cout<<"NO!!!";return 0;}应该就好了


by guojiahong @ 2024-09-22 13:52:47

@jaspersgr114514


by jaspersgr114514 @ 2024-09-22 13:53:51

ok, thankyou


by jaspersgr114514 @ 2024-09-22 13:57:08


| 下一页