ccf 2019.12.15 报数 回收站地址(python)

现在还没有题目出来,但是成绩出来了
第3题花了两小时,样例都是对的,结果0分
第五题20分,最后220,我心态炸了

1,2题都a了


报数

遇到7和7的倍数跳过
输入: 报的个数
输出:甲乙丙丁四人跳过过多少次

很简单,一个count做记录,一个while循环做遍历

n=int(input())
count=[0,0,0,0]
number=1
while n>0:
    if (number>=7 and number%7==0) or ('7' in str(number)) :
        count[(number%4)-1]+=1
    else:
        n-=1
    number+=1
for i in count:
    print(i)

回收站地址

关键在于先判断是否符合回收站的标准,也就是上下左右都有垃圾
然后在从符合标准的位置判断四个对角的分数即可

为了方便,将两个函数单独拆开

n=int(input())
position=[]
res=[0,0,0,0,0]
def adj(x,y,p):
    l=[x-1,y]
    r=[x+1,y]
    t=[x,y-1]
    b=[x,y+1]
    if l in p and r in p and t in p and b in p:
        return True
    else:
        return False
def count(x,y,p,res):
    lt=[x-1,y-1]
    rt=[x+1,y-1]
    lb=[x-1,y+1]
    rb=[x+1,y+1]
    pos=[lt,rt,lb,rb]
    count=0
    for i in range(len(pos)):
        if pos[i] in p:
            count+=1
    res[count]+=1
for i in range(n):
    position.append(list(map(int,input().split())))

for p in position:
    if  p[0]*p[1]==0:   #判断是否在边界处
        continue
    if adj(p[0],p[1],position):  #判断是否符合标准
        count(p[0],p[1],position,res)   #计算分数
for i in res:
    print(i)

等题目出来了再更新

发布了106 篇原创文章 · 获赞 89 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/qq_37465638/article/details/103579423