没有白走的路,每一步都算数🎈🎈🎈
⭐⭐⭐+⭐⭐⭐=⭐⭐⭐
每一个星星⭐代表着一个数字,这9个数字代表着1~9这9个不同的数字。问这样的组数有多少?
注意:
295 + 173 = 468
173 + 295 = 468
表示两组,且数字中不能含有’0‘
省略,不需要输入
输出组数cnt
样例输入输出: 样例输入: 样例输出:
考虑到这是一道填空题,于是打算疯狂构造函数的方式,写两个函数,第一个函数isduzi用来判断这个三位数是不是满足第一条规则,即每个数字是不是不同,每个数字是不是都是在1到9.如果不是,返回0。
第二个函数用来判断这两个三位数的每个数字是不是不一样,如果三个数字每两个都满足此函数,那么组数加一。
最后一步注意for循环中的i的值,j的值,i+j的值要满足小于987然后就成功。
第一个函数isduzi(x):
def isduzi(x):
a = x//100
b = x//10%10
c = x%10
if a == 0:
return 0
if b == 0:
return 0
if c == 0:
return 0
elif a!=b:
if b!=c:
if c!=a:
return 1
return 0第二个函数isnsame(x,y):
def isnsame(x,y):
a1,a2= x//100,y//100
b1,b2 = x//10%10,y//10%10
c1,c2 = x%10,y%10
if a1 != a2 and a1!=b2 and a1!=c2\
and b1!=a2 and b1!=b2 and b1!= c2\
and c1!=a2 and c1!=b2 and c1!=c2:
return 1
else:
return 0#算式问题
import os
import sys
cnt = 0
def isduzi(x):
a = x//100
b = x//10%10
c = x%10
if a == 0:
return 0
if b == 0:
return 0
if c == 0:
return 0
elif a!=b:
if b!=c:
if c!=a:
return 1
return 0
def isnsame(x,y):
a1,a2= x//100,y//100
b1,b2 = x//10%10,y//10%10
c1,c2 = x%10,y%10
if a1 != a2 and a1!=b2 and a1!=c2\
and b1!=a2 and b1!=b2 and b1!= c2\
and c1!=a2 and c1!=b2 and c1!=c2:
return 1
else:
return 0
for i in range(123,988):
if(isduzi(i)):
for j in range(124,988):
if (isduzi(j)) and isnsame(i,j):
if (isduzi(i+j)):
if isnsame(i,i+j) and isnsame(j,i+j) and (i+j)<=987:
cnt+=1
## print(i,j,i+j)
print(count)摘自《《晚熟的人》》:
我要有做自己的自由,敢做自己的勇气。