def include_2(num):
while(num>0):
p = num % 10
if p==2:
return True
num = num // 10
return False
ans=0
for i in range(1,2021):
if include_2(i):
ans+=1
print(ans)
试题B:合数个数
def is_he(n):
for i in range(2,n//2+1):
if(n%i == 0):
return True
return False
ans = 0
for i in range(3,2021):
if is_he(i):
ans+=1
ans+=0
print(ans)
试题C:阶乘约数
import itertools
import math
def fac(num):
if(num>1):
return num * fac(num-1)
return 1
lst = [i for i in range(2,101)]
print(lst)
num = set()
for i in range(2,101):
for l in itertools.combinations(lst,i):
count = 1
for j in l:
count*=j
num.add(count)
print(num)
print(len(num))
试题D:本质上升序列
s='tocyjkdzcieoiodfpbgcncsrjbhmugdnojjddhllnofawllbhfiadgdcdjstemphmnjihecoapdjjrprrqnhgccevdarufmliqijgihhfgdcmxvicfauachlifhafpdccfseflcdgjncadfclvfmadvrnaaahahndsikzssoywakgnfjjaihtniptwoulxbaeqkqhfwl'
dp=[1]*len(s)
for i in range(len(s)):
for j in range(i):
if s[i]>s[j]:
dp[i]+=dp[j]
if s[i]==s[j]:
dp[i]-=dp[j]
print(sum(dp))
试题E:玩具蛇
nu=0
f=[[0,1],[1,0],[-1,0],[0,-1]]
def dfs(m,x,y):
global nu
if m==15:
nu+=1
return
for i in f:
if -1<x+i[0]<4 and -1<y+i[1]<4 and d[x+i[0]][y+i[1]]==0:
d[x][y]=1
dfs(m+1,x+i[0],y+i[1])
d[x][y]=0
for i in range(4):
for i1 in range(4):
d=[[0 for i1 in range(4)]for i in range(4)]
dfs(0,i,i1)
print(nu)
试题F:天干地支
lst = []
for x in range(3):
if x % 2 == 0:
for y in range(2,-1,-1):
lst.append((x,y))
else:
for y in range(3):
lst.append((x,y))
print(lst)
试题G:重复字符串
k=int(input())
s=input()
q1=0 #总修改次数
m=len(s)//k
if len(s)%k!=0:
print("1")
else:
for i in range(m): #依次历遍列
d={}
for j in range(i,len(s),m): #依次历遍每个数
d[s[j]]=d.get(s[j],0)+1 #计数
d=list(d.items())
d.sort(key=lambda k:k[1]) #排序
q1+=k-d[-1][1] #加上 总数减去最大重复字符数
print(q1)
Comments NOTHING