首先是之前用c语言写过的一个版本
用到了乘1002003的方法:
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long x;
int i,t=0,b,c,m=0,j;
bool cf=false;
int a[9]={0};
for(i=123;i<=329;i++)
{
x=i*1002003;
while(x>0)
{
a[m]=x%10;
m++;
x=x/10;
}
for(t=0;t<8&&!cf;t++)
{
for(j=t+1;j<9&&!cf;j++)
{
if(a[t]==a[j]||a[t]==0||a[j]==0)
{cf=true;}
}
}
if(!cf){cout<<i<<" "<<i*2<<" "<<i*3<<endl;}
cf=false;m=0;
}
return 0;
}
然后是极简的python解法,利用到了集合去重复(人生苦短,请用python!!!)
for a in range(123,334):
b=str(2*a)
c=str(3*a)
a=str(a)
s={a[0],a[1],a[2],b[0],b[1],b[2],c[0],c[1],c[2]}
if len(s) == 9 and("0" not in s):
print(int(a),int(b),int(c))
编程过程中遇到的python语法问题:
for循环,range()函数:https://www.runoob.com/python/python-func-range.html
print语句:https://www.runoob.com/w3cnote/python3-print-func-b.html