幽灵特工 @ 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 Dimly_dust @ 2020-07-31 18:25:19
输入
by 幽灵特工 @ 2020-07-31 18:25:22
@Dimly_dust 在哪里判什么等?能说详细点吗
by IceYukino @ 2020-07-31 18:25:23
@Dimly_dust 嗯
by 幽灵特工 @ 2020-07-31 18:26:18
@Dimly_dust 我觉得不能特判哦, 123 456 789 只是一组,还有 125 346 789之类的
by IceYukino @ 2020-07-31 18:26:40
@幽灵特工 这个数据点只有这个一组
by Dimly_dust @ 2020-07-31 18:26:44
@幽灵特工 输入后加个这个
if(A==123&&B==456&&C==789)
{
cout<<"123 456 789"<<endl;
return 0;
}
by IceYukino @ 2020-07-31 18:27:02
正解
by 幽灵特工 @ 2020-07-31 18:27:04
@Dimly_dust 我觉得不能特判哦
by 幽灵特工 @ 2020-07-31 18:28:16
虽然题目的测试点是123 456 789 特判一下就会全部AC 但是我想知道 对于124 356 789 这样的输入 我该怎么改进
by Dimly_dust @ 2020-07-31 18:28:19
@幽灵特工 这种玄学是比较奇葩的,一没有数组越界,二没有除以零,三没有自然溢出。。。