参考代码:
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语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:442 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:982 |
【亲和数】 (C语言代码)浏览:538 |
母牛的故事 (C语言代码)浏览:587 |
1011题解浏览:810 |
关于float,double变量的几点说明浏览:1922 |
简单的a+b (C语言代码)浏览:436 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:746 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:643 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:2200 |