1.
以下是一个 25 行 25 列的字母矩阵,全部由字母 A 和 B 组成。
AAAAAAABABBAABABABAAAAAAA
ABBBBBABBAABBBBBABABBBBBA
ABAAABABBBABAABBBBABAAABA
ABAAABABBBBBAABAABABAAABA
ABAAABABBABABBABABABAAABA
ABBBBBABBBABAABBBBABBBBBA
AAAAAAABABABABABABAAAAAAA
BBBBBBBBABAABABBBBBBBBBBB
AABAABABBAAABBAAABABBBBBA
ABBABABBBABBAAAABBBBAAAAB
BBBBAAABABAABABAABBBAABBA
BBAABABABAAAABBBAABBAAAAA
ABABBBABAABAABABABABBBBBA
AAAABBBBBABBBBAAABBBABBAB
AABAABAAABAAABAABABABAAAA
ABBBBBBBBABABBBBABAABBABA
ABBBAAABAAABBBAAAAAAABAAB
BBBBBBBBABBAAABAABBBABBAB
AAAAAAABBAAABBBBABABAABBA
ABBBBBABBAABABAAABBBABBAA
ABAAABABABBBAAAAAAAAAABAA
ABAAABABABABBBABBAABBABAA
ABAAABABBABBABABAABAABAAA
ABBBBBABABBBBBABBAAAABAAA
AAAAAAABAABBBAABABABBABBA
请问在这个矩阵中有多少个字母A?
s=open('C:\\Users\\10698\\Desktop\\test.txt')
f=list(s)
res=[]
for i in range(len(f)):
res+=f[i]
print(res.count('A'))
num=[]
cnt=0
with open('22.txt') as f:
for line in f.readlines():
for i in range(len(line)):
if line[i]=='A':
cnt+=1
print(cnt)
2.
如果一个整数的某个数位包含 2 ,则称这个数为一个“最2数字”。例如:102、2021 都是最2数字。
请问在 1(含) 到 2021(含) 中,有多少个最2数字。
res=0
for i in range(1,2022):
c=i
while c:
a=c%10
if a==2:
res+=1
break
c//=10
print(res)
nums=[]
with open('2020.txt') as f:
for line in f.readlines():
nums.append(list(line.strip()))
res = 0
for i in range(len(nums)):
for j in range(len(nums)-3):
if nums[i][j] == '2' and nums[i][j+1] == '0' and nums[i][j+2] == '2' and nums[i][j+3] == '0':
res +=1
for i in range(len(nums)-3):
for j in range(len(nums)):
if nums[i][j] == '2' and nums[i+1][j] == '0' and nums[i+2][j] == '2' and nums[i+3][j] == '0':
res += 1
for i in range(len(nums)-3):
for j in range(len(nums)-3):
if nums[i][j] == '2' and nums[i+1][j+1] == '0' and nums[i+2][j+2] == '2' and nums[i+3][j+3] == '0':
res += 1
print(res)
a=[0 for i in range(20190324+5)]
a[1]=1
a[2]=1
a[3]=1
for i in range(4,20190324+1):
a[i]=(a[i-1]+a[i-2]+a[i-3])%10000
print(a[20190324])
N=2019
num=[]
for a in range(1,N+1):
b=a
while b:
c=b%10
if c==2 or c==0 or c==1 or c==9:
num.append(a)
break
b//=10
#print(sum(num))
cnt=0
for i in range(len(num)):
cnt+=num[i]*num[i]
print(cnt)
s=input()
cnt=[0 for i in range(26)]
for i in range(len(s)):
cnt[ord(s[i])-ord('a')]+=1
maxm=max(cnt)
for i in range(len(s)):
if cnt[i]==maxm:
print(chr(ord('a')+i))
break
print(maxm)
n=1200000
i=1
cnt=0
while i<=n**0.5:
if n%i==0:
cnt+=2
i+=1
if n**0.5==int(n**0.5):
cnt-=1
print(cnt)
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
jige=0
youxiu=0
for i in range(n):
if a[i]>=60:
jige+=1
if a[i]>=85:
youxiu+=1
print("%d%%"%(round(jige/n*100)))
print("%d%%"%(round(youxiu/n*100)))
from datetime import date,timedelta
ed=date(2020,10,1)#结束日期
st=date(2000,1,1)#开始日期
res=0
while st<=ed:
if st.day==1 or st.weekday()==0:#或者用st.isoweekday()==1
res+=2
else:
res+=1
st+=timedelta(days=1)
print(res)
a=[]
n=int(input())
for i in range(n):
a.append(int(input()))
summ=sum(a)
maxm=max(a)
minm=min(a)
print(maxm)
print(minm)
print("%.2f"%(summ/n))
m=20
n=20
cnt=m*m+n*n*0.5+2*m*n-m+0.5*n+1
print(int(cnt))
a=20
b=20
summ=0
c=a+b-1
for i in range(1,c+1):
summ+=i
cnt=0
if summ%2==0: #最后一个数为偶数
cnt=summ-b+1
else: #最后一个数为奇数
cnt=summ-a+1
print(cnt)
def gcd(a, b):
return a if b == 0 else gcd(b, a % b)
ans = 0
for zi in range(1, 2021):
for mu in range(1, 2021):
if gcd(zi, mu) == 1:
ans += 1
print(ans)
x=[i for i in range(1,2021)]
cnt=0
for y in x:
j=y
while j:
a=j%10
if a==2:
cnt+=1
j//=10
print(cnt)
try:
while True:
n=int(input())
len=int(n**0.5)
flag=0
for a in range(1,len+1):
for b in range(a,len+1):
for c in range(b,len+1):
if a*a+b*b+c*c==n:
print("%d %d %d"%(a,b,c))
flag=1
if flag==0:
print("No Solution")
except:
pass
注意读题,求的不是七周中位数的和,而是七周中位数的中位数的最大值
如图
a,b,c,x,e,f,g分别是每周的中位数。
而x是a,b,c,x,e,f,g是这七周的每一周的中位数的中位数
题目的要求是让我们最大化这个x;
我们可以假定x已经是我们要求的值,那么为了让x符合题目信息,我们必须让第4周的后3天,第5,6,7周的后4天都大于这个值。
那么很显然有15个数比x大,那么x就等于49 - 15 = 34;
n = 2019
s = ''
while n > 0:
n -= 1
a, b = n//26, n%26
s += chr(b+ord('A'))
n = a
print(s[::-1])
num=[]
with open('team.txt') as f:
for line in f.readlines():
num.append(list(line.split()))
flag=[0 for i in range(len(num)+1)]
ssum=0
maxx=0
last=0
for i in range(len(num)):
if int(num[i][1])>maxx and flag[i]==0:
maxx=int(num[i][1])
flag[last]=0
flag[i]=1
last=i
ssum+=maxx
maxx=0
last=0
for i in range(len(num)):
if int(num[i][2])>maxx and flag[i]==0:
maxx=int(num[i][2])
flag[last]=0
flag[i]=1
last=i
ssum+=maxx
maxx=0
last=0
for i in range(len(num)):
if int(num[i][3])>maxx and flag[i]==0:
maxx=int(num[i][3])
flag[last]=0
flag[i]=1
last=i
ssum+=maxx
maxx=0
last=0
for i in range(len(num)):
if int(num[i][4])>maxx and flag[i]==0:
maxx=int(num[i][4])
flag[last]=0
flag[i]=1
last=i
ssum+=maxx
maxx=0
last=0
for i in range(len(num)):
if int(num[i][5])>maxx and flag[i]==0:
maxx=int(num[i][5])
flag[last]=0
flag[i]=1
last=i
ssum+=maxx
maxx=0
last=0
print(ssum)
N=int(input())
ssum=0
for i in range(1,N+1):
a=i
while a:
b=a%10
if b==2 or b==0 or b==1 or b==9:
ssum+=i
break
a//=10
print(ssum)
def check(a):
while a:
b=a%10
if b==2 or b==4:
return 0
a//=10
return 1
cnt=0
for i in range(1,2019+1):
for j in range(i+1,2019+1):
k=2019-i-j
if i
n=int(input())
a=list(map(int,input().split()))
j=1
deep=1
ff=0
maxx=0
i=0
while imaxx:
maxx=sum(b)
ff=deep
i+=j
j*=2
deep+=1
print(ff)
a=2019
b=324
cnt=0
while a and b:
cnt+=1
a=a-b
a,b=max(a,b),min(a,b)
print(cnt)
from math import sqrt
def check(n):
i=2
while i<=sqrt(n):
if n%i==0:
return 0
i+=1
return 1
cnt=1 #2是第一个质数,偶数
i=3
while True:
if check(i):
cnt+=1
if cnt==2019:
print(i)
break
i+=2
m,n=map(int,input().split())
a=[]
for i in range(m):
a.append(list(map(int,input().split())))
#找规律
# (1,1)->(1,3) (1,2)->(2,3) (1,4)->(4,3)
# (2,1)->(1,2) ... (2,4)->(4,2)
# (3,1)->(1,1) ... (3,4)->(4,1)
# (2,2)->(2,2) (2,3)->(3,2)
# m=3,n=4 顺时针90度,行=原来的列,列=n-原来的行
b=[[0 for i in range(m)] for i in range(n)]
for i in range(m):
for j in range(n):
b[j][m-1-i]=a[i][j]
for i in range(n):
for j in range(m):
print(b[i][j],end=" ")
print()
g=[[float('inf') for i in range(26)] for j in range(26)]
st=[0 for i in range(26)]
n=19 #共有19个点
def dijkstra():
dist=[float('inf') for i in range(26)]
dist[1]=0
for i in range(n):
t=-1
for j in range(1,n+1):
if (not st[j]) and (t==-1 or dist[t]>dist[j]):
t=j #核心,加入当前未加入中距离最小的点
for j in range(1,n+1): #每次加入一个点,更新值
dist[j]=min(dist[j],dist[t]+g[t][j])
st[t]=1
return dist[19]
def add(a,b,c):
g[a][b]=c
g[b][a]=c
#输入距离
add(1,2,2)
add(1,3,1)
add(1,4,1)
add(1,5,1)
add(2,7,1)
add(2,10,2)
add(3,6,3)
add(3,7,3)
add(3,4,3)
add(4,5,1)
add(4,7,2)
add(4,8,1)
add(4,9,2)
add(5,8,1)
add(5,9,3)
add(6,7,1)
add(6,10,1)
add(7,9,3)
add(7,11,2)
add(8,9,1)
add(8,12,2)
add(9,13,3)
add(10,19,2)
add(11,12,3)
add(11,14,1)
add(11,16,2)
add(12,13,1)
add(12,18,1)
add(13,17,1)
add(13,19,1)
add(13,14,2)
add(14,16,1)
add(15,16,1)
add(15,17,1)
add(15,18,3)
add(18,19,1)
#迪杰斯特拉模板再背一遍
print(dijkstra())
n="LANQIAO"
ssum=0
for i in range(len(n)):
ssum+=(ord(n[i])-ord('A')+1)*pow(26,len(n)-1-i)
print(ssum)