参考代码:
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 人评分
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:812 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1199 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:682 |
用筛法求之N内的素数。 (C语言代码)浏览:880 |
求圆的面积 (C语言代码)浏览:1746 |
1054题解浏览:508 |
局部变量作函数返回值的问题浏览:1020 |
2006年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:722 |
C语言程序设计教程(第三版)课后习题12.5 (C语言代码)浏览:792 |
矩阵转置 (C语言代码)浏览:851 |