赞
踩
目录
- '''2020.txt'''
-
- 220000
- 000000
- 002202
- 000000
- 000022
- 002020
-
- def get_n(i,j): #为了防止超出索引,必须要try和except!
- n = 0
- try:
- if ls[i][j+1] =='0': #右边
- if ls[i][j+2] =='2':
- if ls[i][j+3] =='0':
- n +=1
- ## print(ls[i][j+1],ls[i][j+2],ls[i][j+3])
- except IndexError:
- pass
- try:
- if ls[i+1][j] =='0': #下边
- if ls[i+2][j] =='2':
- if ls[i+3][j] =='0':
- n +=1
- ## print(ls[i+1][j],ls[i+2][j],ls[i+3][j])
- except IndexError:
- pass
- try:
- if ls[i+1][j+1] =='0': #右下边
- if ls[i+2][j+2] =='2':
- if ls[i+3][j+3] =='0':
- n +=1
- ## print(ls[i+1][j+1],ls[i+2][j+2],ls[i+3][j+3])
- except IndexError:
- pass
-
- return n
-
-
-
- f = open('2020.txt','r')
- ls = []
- for i in f:
- ls.append(i.strip())
- ##print(ls)
-
- num = 0
- lens = len(ls)
- for i in range(lens):
- leni = len(ls[i])
- for j in range(leni):
- if ls[i][j] =='2':
- num += get_n(i,j)
-
- f.close()
- print(num)
- n = int(input('n行(1<=n<=34):'))
- ls = []
-
- for i in range(1,n+1): #生成结果列表的存储空间(用0代替)
- ls0 = []
- for j in range(i):
- ls0.append(0)
- ls.append(ls0)
- ##print(ls)
-
- for i in range(n): #往存储空间赋值
- for j in range(len(ls[i])):
- if i+1 <=2 or j==0 or j==len(ls[i])-1: #12行或者每行的头尾元素都是1
- ls[i][j] = 1
- elif i+1 >2:
- ls[i][j] = ls[i-1][j-1]+ls[i-1][j]
- ##print(ls)
-
-
- for i in range(n):
- ls[i] = list(map(str,ls[i])) #把列表的数字转化成字符串,方便输出
- ##print(ls)
- for j in range(n):
- print(' '.join(ls[j]))
- #'''直接输出答案'''
-
- print((2019 +1)//2)
-
-
- '''
- 先说一下,二叉树的性质:
- 》》叶子节点n0 = 度为2的节点数n2 +1
- 》》2019(N总) = 叶子节点N0 + 度为1的节点N1+ 度为2的节点N2
- (单分支结点n1如果存在那么n1等于1,如果不存在n1等于0)
- 由上可得:n总 = n0 + n1 + (n0 -1)
- 现问的是,2019个节点的完全二叉树,最多叶子结点是多少?
- n总 +1 = 2n0 + n1(所以此时n1应该取0,即 n0最大为 1010)
- 答:叶子结点最多有1010个。
- '''
别忘了,二叉树的性质:
》》叶子节点n0 = 度为2的节点数n2 +1
》》2019(N总) = 叶子节点N0 + 度为1的节点N1+ 度为2的节点N2
(单分支结点n1如果存在那么n1等于1,如果不存在n1等于0)
- s = input('一个单词,只小写字母:')
- ls = ['a','e','i','o','u']
- ##print(ls)
-
- ls0 = [] #单词根据拼音字母 分段的结果存入ls0
- ls1,ls2 = [],[] #辅音组ls1,元音组ls2
- for i in range(len(s)):
- if s[i] not in ls: #如果是辅音
- if ls2 != []:
- ls0.append(ls2)
- ls2 = []
- ls1.append(s[i]) #辅音加入列表ls1
- elif s[i] in ls: #如果是元音
- if ls1 != []:
- ls0.append(ls1) #前面是辅音 现遍历到元音了,辅音组加入ls0
- ls1 = [] #辅音组加入ls0之后清空ls1
- ls2.append(s[i]) #辅音加入列表ls2
-
- if i ==len(s)-1: #结尾,往ls0加入最后一段音组
- if ls2 != []:
- ls0.append(ls2)
- elif ls1 != []:
- ls0.append(ls1)
- ##print(ls0)
-
- if len(ls0)==4: #如果输入单词s的音组分段刚好是“辅,元,辅,元”,那就刚好是4组
- print('yes')
- else:
- print('no')
- sex,fh,mh = map(eval,input('空格分开的三个数:整数,小数,小数:').split())
- ##print(sex,fh,mh)
-
- h_1,h_0 = 0.0, 0.0
- if sex ==1:
- h_1 = (fh +mh)/2 *1.08
- print('{:.3f}'.format(h_1))
- elif sex ==0:
- h_0 = (fh *0.923 +mh)/2
- print('{:.3f}'.format(h_0))
题目描述: 1200000有多少个约数(只计算正约数)
注意:约数就是因数的意思(只要%取余==0都算)【要注意对称性,到根号的那个整数结束】
关于约数,质数,质因数的补充说明可以看下面这个链接》》
- num= 0
- # 【要注意对称性,到根号的那个整数结束】
- for i in range(1, int(float(1200000)**0.5) +1):
- if 1200000 % i == 0:
- num+= 2
- print(num)
- def fj(x):
- for i in range(2, int(x**0.5)+1):
- if x % i == 0:
- ls.append(i)
- fj(x // i)
- return
- ls.append(x)
-
-
- n = int(input())
- ls = []
-
- fj(n)
- print(max(ls))
- n = int(input())
- m = 0
- while n:
- n -=1
- m +=1
- if m %3==0:
- m +=1
-
- print(m)
- a,b,n = map(int,input().strip().split())
-
- week_do = a*5 +b*2 #坐满一个星期,能做多少
- week = n //week_do #多少个能坐满一个星期的week
-
- day = week *7
- last_do = n -week*week_do #最后剩下那点
- if last_do !=0:
- b_do = last_do -a*5
-
- if b_do >0: #如果周末要做
- a_day =5
- b_day = b_do //b
- if (b_do -b*b_day)/b >0:
- b_day +=1
- elif b_do <=0:
- b_day =0
- a_day = last_do //a
- if (last_do -a*a_day)/a >0:
- a_day +=1
-
- else:
- a_day,b_day =0,0 #别忘记了else情况
-
- day += a_day +b_day
- print(day)
- '''根据2020的年份,先手算出来甲子是多少(2044),这样才可以正常列表索引'''
-
-
- tian = ['jia','yi','bing','ding','wu','ji','geng','xin','ren','gui']
- di = ['zi','chou','yin','mao','chen','si','wu','wei','shen','you','xu','hai']
-
- n = int(input())
- s = (n-2044) %60 # 这里一开始我加了绝对值 abs(),结果发现加了反而错?至于为什么我还不清楚
-
- t = s %10
- d = s %12
- print(tian[t],di[d],sep='')
———————————————— Thanks♪(・ω・)ノ感谢阅读 ———————————————
》》》做法来自笔者个人:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。