Languages: Python
Categories: 其他

# _*_ coding:utf-8 _*_

# 1.九宫格
'''
1至9九个数字，横竖都有3个格，

'''
li = []
s = set()
number = 1

for x in range(1,10):
for z in range(1,10):
y = 10-z
w = 10-x
if 0<15-x-y<10 and 0<15-x-z<10 :
li.append(x)
li.append(15-x-y)
li.append(y)
li.append(15-x-z)
li.append(5)
li.append(15-y-w)
li.append(z)
li.append(15-z-w)
li.append(w)
if len(s) == 9:
print('---- 第 %d 个 ----' % number)
for i in range(3):
for k in range(3):
if k == 2:
print(li[i*3+k],end='')
else:
print(li[i*3+k],end=' ')
print()
print('')
number+=1
s.clear()
li.clear()

#2.寻找班级里面名字最长的人
'''

names=(' Kunpen Ji, Li XIAO, Caron Li,'
' Dongjian SHI, Ji ZHAO, Fia YUAN Y,'
' Wenxue DING, Xiu XU, Haiying WANG, Hai LIN,'
' Jey JIANG, Joson WANG E,'
' Aiyang ZHANG, Haiying MENG,'
' Jack ZHANG E, Chang Zhang, Coron ZHANG')

'''
names=(' Kunpen Ji, Li XIAO, Caron Li,'
' Dongjian SHI, Ji ZHAO, Fia YUAN Y,'
' Wenxue DING, Xiu XU, Haiying WANG, Hai LIN,'
' Jey JIANG, Joson WANG E,'
' Aiyang ZHANG, Haiying MENG,'
' Jack ZHANG E, Chang Zhang, Coron ZHANG')

import string
s = string.printable[36:62]
m = names.split(r",")
li = []
li2 = [[''] for i in range(26)]
zhang = []
for i in m:
i = i[1:]
li.append(i)

n = i.split(' ')
if len(n[-1])>1:
k = n[-1]
else:
k = n[-2]

if li2[s.index(k[0])][0] == '':
li2[s.index(k[0])][0] = i
else:
li2[s.index(k[0])].append(i)

if k.upper() == 'ZHANG':  #ZHANG个数
zhang.append(i)

li3 = []
for i in li2:
if i!=[''] :
li3.extend(i)
print("排序 = " ,li3)

li.sort(key=len,reverse=True)

h = len(li[0])
li4 = []
for i,k in enumerate(li) :
ks= k.split(' ')
if i+1<len(li) and len(ks[-1])==1  :
if len(' '.join(ks[:-1])) > len(li[i+1]) :
li4.append(k)
else  :
if len(k)  == h:
li4.append(k)
print('最长的名字 = ' ,li4)

print('ZHANG个数 = %s，分别是：%s' % (len(zhang),zhang))