From 6f7852cc3cbcf4c3a607ac405df236a54a13aee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=80=9D=E8=BE=B0?= <wsc2333333@163.com> Date: Tue, 23 Nov 2021 16:17:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'sy5-12.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sy5-12.py | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 sy5-12.py diff --git a/sy5-12.py b/sy5-12.py deleted file mode 100644 index 63a2009..0000000 --- a/sy5-12.py +++ /dev/null @@ -1,33 +0,0 @@ -def isTgs(n):#判断一个数是否是同构数,是则返回True,不是则返回False - m=n*n - return str(m)[-len(str(n)):]==str(n) - -def check(instr):#检查instr是否合法,合法则返回字符串对应的整数,不合法返回错误代码。 - if len(instr)>2 or len(instr)<1: - return -1 - elif not instr.isnumeric() : #输入的是非数字字符 - return -2 - else: - return int(instr) -def getTgs():#输入一组数据到-1结束,将其中1~2位的同构数加入到一个列表后返回列表 - L=[] - s=input().strip() - while s!="-1": - n=check(s) - if n>0 and isTgs(n): - L.append(n) - s=input().strip() - return L - -def main():#获取同构数,输出有序的不重复的同构数 - L=getTgs() - if len(L)==0: - print("没有同构数") - else: - L= list(set(L)) #去重复 - L.sort() - print("同构数有:",end="") - for i in L: - print(i,end=' ') - -main()