80720 - 同测活动第4场阅读程序1
统计题目(材料题)
(1)
01 #include <iostream>
02 using namespace std;
03 int main() {
04 int n;
05 cin >> n;
06 int a[100][100];
07 int b[100][100];
08 for (int i = 0; i < n; i++) {
09 for (int j = 0; j < n; j++) {
10 cin >> a[i][j];
11 b[i][j] = 0;
12 }
13 }
14 for (int i = 0; i < n; i++) {
15 for (int j = 0; j < n; j++) {
16 if (i > 0 && a[i][j] == a[i-1][j]) b[i][j]++;
17 if (i < n-1 && a[i][j] == a[i+1][j]) b[i][j]++;
18 if (j > 0 && a[i][j] == a[i][j-1]) b[i][j]++;
19 if (j < n-1 && a[i][j] == a[i][j+1]) b[i][j]++;
20 }
21 }
22 int ans = 0;
23 for (int i = 0; i < n; i++) {
24 for (int j = 0; j < n; j++) {
25 if (b[i][j] >= 2) ans++;
26 }
27 }
28 cout << ans << endl;
29 return 0;
30 }
假设输入的 n 为正整数,且输入的 a[i][j] 均为不超过100的非负整数,完成下面的判断题和单选题。

关注我们