|
发表于 2020-5-5 00:13:07
|
显示全部楼层
- def P389(lit):
- n = 0
- row, column = len(lit), len(lit[0])
- for r in range(row):
- for c in range(column):
- i = 0
- if lit[r][c] == 0:
- continue
- else:
- if r != 0 and lit[r-1][c] == 1:
- i += 1
- ## print('1:',i,end=' ')
- if c != 0 and lit[r][c-1] == 1:
- i += 1
- ## print('2:',i,end=' ')
- if r != row - 1 and lit[r+1][c] == 1:
- i += 1
- ## print('3:',i,end=' ')
- if c != column - 1 and lit[r][c+1] == 1:
- i += 1
- ## print('4:',i)
- n += 4-i
- ## print('n:',n)
- return n
- lit = [
- [0, 1, 0, 0],
- [1, 1, 1, 0],
- [0, 1, 0, 0],
- [1, 1, 0, 0]
- ]
- print(P389(lit))
复制代码
萌新求大佬赐教 |
|