201912-2 回收站选址

题目描述

201912-2 回收站选址_第1张图片

我的解

total=int(input())
place=[]
score=[0,0,0,0,0]
for i in range(total):
    temp=input().split(' ')
    temp=[int(x) for x in temp]
    place.append(temp)
for item in place:
    x=item[0]
    y=item[1]
    count=0
    for item1 in place:
        if item1[0]==x or item1[1]==y:
            if item1[0]==x:
                if item1[1]==y+1 or item1[1]==y-1:
                    count+=1
            else:
                if item1[0] == x + 1 or item1[0] == x - 1:
                    count+=1
    if count==4:
        count1=0
        for item1 in place:
            if (item1[0]==x+1 and item1[1]==y+1) or (item1[0]==x+1 and item1[1]==y-1) or (item1[0]==x-1 and item1[1]==y+1) or (item1[0]==x-1 and item1[1]==y-1):
                count1+=1
        score[count1] += 1


for i in score:
    print(i)

他人的解

n = int(input())
L = []
scoreList = [0]*5
for i in range(n):
    (x,y) = map(str, input().split())
    # 需要判断是否为整数
    if '.' not in x and '.' not in y:
        x = int(x)
        y = int(y)
        L.append((x,y))
for (x,y) in L:
    if (x-1, y) in L and (x+1, y) in L and (x, y-1) in L and (x,y+1) in L:
        score = 0
        if (x-1,y-1) in L:
            score += 1
        if (x-1,y+1) in L:
            score += 1
        if (x+1,y-1) in L:
            score += 1
        if (x+1,y+1) in L:
            score += 1
        scoreList[score] += 1
for i in range(5):
    print(scoreList[i])
原文链接 https://blog.csdn.net/Mia0717/article/details/104070355

你可能感兴趣的:(201912-2 回收站选址)