1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 15:48:42 +00:00

【实践课内】8.数组2

This commit is contained in:
Baoshuo Ren 2024-11-13 10:23:33 +08:00
parent aabd2bca7b
commit a32c304631
Failed to extract signature
8 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#include <stdio.h>
int m, n, matrix[25][25], flag;
int main() {
scanf("%d%d", &m, &n);
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &matrix[i][j]);
}
}
for (int i = 2; i <= m - 1; i++) {
for (int j = 2; j <= n - 1; j++) {
if (matrix[i][j] > matrix[i - 1][j]
&& matrix[i][j] > matrix[i + 1][j]
&& matrix[i][j] > matrix[i][j - 1]
&& matrix[i][j] > matrix[i][j + 1]) {
printf("%d %d %d\n", matrix[i][j], i, j);
flag = 1;
}
}
}
if (!flag) {
printf("None %d %d\n", m, n);
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 KiB

View File

@ -0,0 +1,21 @@
#include <stdio.h>
int main() {
int m, n;
scanf("%d%d", &m, &n);
for (int i = 1; i <= m; i++) {
int x, sum = 0;
for (int j = 1; j <= n; j++) {
scanf("%d", &x);
sum += x;
}
printf("%d\n", sum);
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 KiB

View File

@ -0,0 +1,35 @@
#include <stdio.h>
int t, n, mat[15][15];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &mat[i][j]);
}
}
int flag = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
if (mat[i][j] != 0) {
flag = 0;
}
}
}
if (flag) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

View File

@ -0,0 +1,30 @@
#include <stdio.h>
int n, k, tag_count[1005], max, max_id;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &k);
for (int j = 1; j <= k; j++) {
int x;
scanf("%d", &x);
tag_count[x]++;
}
}
for (int i = 1; i <= 1000; i++) {
if (tag_count[i] >= max) {
max = tag_count[i];
max_id = i;
}
}
printf("%d %d\n", max_id, max);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 KiB