mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-27 02:25:37 +00:00
【实践课内】8.数组2
This commit is contained in:
parent
aabd2bca7b
commit
a32c304631
32
【实践课内】8.数组2/7-1 求矩阵的局部极大值.c
Normal file
32
【实践课内】8.数组2/7-1 求矩阵的局部极大值.c
Normal 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;
|
||||
}
|
BIN
【实践课内】8.数组2/7-1 求矩阵的局部极大值.jpg
Normal file
BIN
【实践课内】8.数组2/7-1 求矩阵的局部极大值.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 375 KiB |
21
【实践课内】8.数组2/7-2 求矩阵各行元素之和.c
Normal file
21
【实践课内】8.数组2/7-2 求矩阵各行元素之和.c
Normal 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;
|
||||
}
|
BIN
【实践课内】8.数组2/7-2 求矩阵各行元素之和.jpg
Normal file
BIN
【实践课内】8.数组2/7-2 求矩阵各行元素之和.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 280 KiB |
35
【实践课内】8.数组2/7-3 判断上三角矩阵.c
Normal file
35
【实践课内】8.数组2/7-3 判断上三角矩阵.c
Normal 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;
|
||||
}
|
BIN
【实践课内】8.数组2/7-3 判断上三角矩阵.jpg
Normal file
BIN
【实践课内】8.数组2/7-3 判断上三角矩阵.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 338 KiB |
30
【实践课内】8.数组2/7-5 点赞.c
Normal file
30
【实践课内】8.数组2/7-5 点赞.c
Normal 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;
|
||||
}
|
BIN
【实践课内】8.数组2/7-5 点赞.jpg
Normal file
BIN
【实践课内】8.数组2/7-5 点赞.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 384 KiB |
Loading…
Reference in New Issue
Block a user