直接暴力枚举!
2024-11-10 19:17:21
发布于:广东
23阅读
0回复
0点赞
遍历次数是,不用担心超时,注意要判断互不相同
#include<bits/stdc++.h>
using namespace std;
int f(int x,int y) {return x*10+y;}
int g(int x,int y,int z) {return x*100+y*10+z;}
int main()
{
int cnt=0;
for (int a=1;a<=9;a++)
{
for (int b=1;b<=9;b++)
{
for (int c=1;c<=9;c++)
{
for (int d=1;d<=9;d++)
{
for (int e=1;e<=9;e++)
{
if (f(a,b)*g(c,d,e)==g(a,d,b)*f(c,e) && a!=b && a!=c && a!=d && a!=e && b!=c && b!=d && b!=e && c!=d && c!=e && d!=e)
{
printf("%d%d%d%d%d\n",a,b,c,d,e);
cnt++;
}
}
}
}
}
}
cout << cnt;
return 0;
}
这里空空如也
有帮助,赞一个