不能对 123 456 789 正确输出

P1618 三连击(升级版)

幽灵特工 @ 2020-07-31 18:05:19

#include<bits/stdc++.h>
using namespace std;

int gcd(int a, int b, int c, int n) {
    if (a % n == 0 && b % n == 0 && c % n == 0) {
        return n;
    }
    else {
        n--;
        gcd(a, b, c, n);
    }
}
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int n = min(A, min(B, C));
    n = gcd(A, B, C, n);
    A /= n;
    B /= n;
    C /= n;
    int f=0;
    for (int i = 123; i < 985; i++) {
        int a = i * A;
        int b = i * B;
        int c = i * C;
        if (100 < a && a < 999 && 100 < b && b < 999 && 100 < c && c < 999) {
            int l[9];
            l[0] = a / 100;
            l[1] = (a % 100) / 10;
            l[2] = (a % 10);
            l[3] = b / 100;
            l[4] = (b % 100) / 10;
            l[5] = b % 10;
            l[6] = c / 100;
            l[7] = (c % 100) / 10;
            l[8] = c % 10;
            int sum = 0;
            int s = 1;
            for (int k = 0; k < 9; k++) {
                sum += l[k];
                s *= l[k];
            }
            if (sum == 45 && s == 362880) {
                cout << a << " " << b << " " << c << " " << endl;
                f = 1;
            }
        }
    }
    if (f == 0) {
        cout << "No!!!" << endl;
    }
}   

by IceYukino @ 2020-07-31 18:17:47

#include<bits/stdc++.h>
using namespace std;

int gcd(int a, int b, int c, int n) {
    if (a % n == 0 && b % n == 0 && c % n == 0) {
        return n;
    }
    else {
        n--;
        gcd(a, b, c, n);
    }
}
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int n = min(A, min(B, C));
    n = gcd(A, B, C, n);
    A /= n;
    B /= n;
    C /= n;
    cout<<A <<" "<<B<<" "<<C<<endl;
    int f=0;
    for (int i = 1; i < 985; i++) {
        int a = i * A;
        int b = i * B;
        int c = i * C;
        if (100 < a && a < 999 && 100 < b && b < 999 && 100 < c && c < 999) {
            int l[9];
            l[0] = a / 100;
            l[1] = (a % 100) / 10;
            l[2] = (a % 10);
            l[3] = b / 100;
            l[4] = (b % 100) / 10;
            l[5] = b % 10;
            l[6] = c / 100;
            l[7] = (c % 100) / 10;
            l[8] = c % 10;
            int sum = 0;
            long long s = 1;
            for (int k = 0; k < 9; k++) {
                sum += l[k];
                s *= l[k];
            }
            if (sum == 45 && s == 362880) {
                cout << a << " " << b << " " << c << " " << endl;
                f=1;             
            }
        }
    }
    if (f == 0) {
        cout << "No!!!" << endl;
    }
}   

我的这个程序在本地可以过,但是在洛谷会RE,等下楼主自己改一下吧


by IceYukino @ 2020-07-31 18:18:03

@demonred 您在说什么?


by IceYukino @ 2020-07-31 18:19:16

@demonred i为什么不能从123开始?i从123开始的话乘上41可能小于999吗?


by 出言不逊王子 @ 2020-07-31 18:19:21

别对线啊


by IceYukino @ 2020-07-31 18:20:23

@出言不逊王子 正解,我也不想对线,我想告诉楼主哪里错了,但是被一个人狂怼,并且说的还是错的?


by 出言不逊王子 @ 2020-07-31 18:22:48

@gqh_蒟蒻_or_大佬 有一说一 我也觉得123开始没问题 这个是特例


by 出言不逊王子 @ 2020-07-31 18:23:01

要特判(


by IceYukino @ 2020-07-31 18:23:15

@出言不逊王子 好吧


by 幽灵特工 @ 2020-07-31 18:23:46

@出言不逊王子 那么输入124 356 789呢 都“特判”吗?


by Dimly_dust @ 2020-07-31 18:25:01

@幽灵特工 这个RE比较玄学,你把123 456 789特判一下return0;吧


上一页 | 下一页