Mei20 @ 2024-09-23 22:37:06
#include <iostream>
#include <cstring>
using namespace std;
int a,b,c,n1,n2,n3,v;
bool e[10],ans;
int main()
{
cin>>a>>b>>c;
for(int i=123;i<=int(1000/c);i++)
{
memset(e,0,sizeof(e));
n1=i;n2=i*b;n3=i*c;v=0;
if(n3>=1000) continue;
e[n1/100]=1;n1%=100;e[n1/10]=1;e[n1%10]=1;
e[n2/100]=1;n2%=100;e[n2/10]=1;e[n2%10]=1;
e[n3/100]=1;n3%=100;e[n3/10]=1;e[n3%10]=1;
for(int j=1;j<=9;j++) v+=e[i];
if(v==9) {
ans=1;
cout<<i<<' '<<i*b<<' '<<i*c<<endl;
}
}
if(!ans) cout<<"No!!!";
return 0;
}
//Subtask #0 3,6,7未过
by kkKscsort @ 2024-09-24 21:18:39
你这个错误很大呀
第一、for(int j=1;j<=9;j++) v+=e[i];
你for的是j 加的是e[i]
第二、你的a是是干什么的,你不能保证a==1
如 123 456 789 你自己试一下
by kkKscsort @ 2024-09-24 21:30:19
#include <iostream>
#include <cstring>
using namespace std;
int a, b, c, n1, n2, n3, v;
int e[10], ans;
int main() {
cin >> a >> b >> c;
for (int i = 123; i <= 999; i++) {
memset(e, 0, sizeof(e));
n1 = i;
n2 = int(1.0*i / a * b);
n3 = int(1.0*i / a * c);
if(n3>=1000){
break;
}
if (n1 / n2 == a / b && n2 / n3 == b / c && n3 / n1 == c / a) {
v = 0;
e[n1 / 100] = 1;
n1 %= 100;
e[n1 / 10] = 1;
e[n1 % 10] = 1;
e[n2 / 100] = 1;
n2 %= 100;
e[n2 / 10 % 10] = 1;
e[n2 % 10] = 1;
e[n3 / 100] = 1;
n3 %= 100;
e[n3 / 10 % 10] = 1;
e[n3 % 10] = 1;
for (int j = 1; j <= 9; j++) {
v += e[j];
}
if (v == 9) {
ans = 1;
cout << i << ' ' << i/a*b << ' ' << i/a*c << endl;
}
}
}
if (!ans) cout << "No!!!";
return 0;
}
by kkKscsort @ 2024-09-24 21:31:03
已经改好了,你对比一下