参考代码:
dx = (-1, 0, 1, 0) dy = (0, -1, 0, 1) def judge(x, y): if x == 0 or x == n - 1 or y == 0 or y == n - 1: return True for d in range(4): tx, ty = x + dx[d], y + dy[d] if 0 <= tx < n and 0 <= ty < n and arr[tx][ty] > 50: return True return False n = int(input()) arr = [list(map(int, input().split())) for _ in range(n)] square = 0 circumference = 0 for i in range(n): for j in range(n): if arr[i][j] <= 50: square += 1 if judge(i, j): circumference += 1 print(square, circumference)
0.0分
0 人评分
点我有惊喜!你懂得!浏览:2240 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:599 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:1055 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:566 |
【出圈】 (C语言代码)浏览:585 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:982 |
DNA (C语言描述,数据结构)浏览:901 |
【金明的预算方案】 (C++代码)浏览:984 |
2005年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:629 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:612 |