vault backup: 2026-01-29 21:02:30

This commit is contained in:
2026-01-29 21:02:30 +08:00
parent 2f8d74a33d
commit 73a50c0303
3 changed files with 54 additions and 11 deletions

View File

@@ -6,9 +6,13 @@ aliases: empty
日期: 2026/1/29
---
**1.定义一个长度为10的数组并从键盘输入10个整数对数组进行赋值并实现下列功能**
1. 判定该数组是否有序
2. 若无序则将数组中的数据进行排序
3. 找出数组中是否存在众数并输出结果
```c
#include <stdio.h>
@@ -98,6 +102,7 @@ int main(int argc, char const *argv[])
```
![700](assets/1-29/file-20260129201415992.png)
**2.定义一个二维数组存储一个3x3的矩阵实现如下功能**
1. 计算矩阵对角元素的和
2. 判断矩阵是否是对称矩阵
```c
@@ -153,12 +158,49 @@ int main(int argc, char const *argv[])
- 报到数字M的倍数员工被淘汰出局
- 从下一位员工继续报数重复步骤2
- 游戏继续直到只剩下K名员工获胜者
```c
```
**4.小刘作为公司的技术骨干编写了一个程序帮助他每次都能处在胜利者中并最终获得晋升资格请你使用C语言编程复现小刘的程序实现以下功能**
*小刘作为公司的技术骨干编写了一个程序帮助他每次都能处在胜利者中并最终获得晋升资格请你使用C语言编程复现小刘的程序实现以下功能*
- 输入总人数N、报数间隔M和获胜人数K
- 计算并输出安全的座位位置最后剩下的K人
```c
#include <stdio.h>
```
int main(int argc, char const *argv[])
{
    int N,M,K;
    printf("请输入参与总人数:");
    scanf("%d",&N);
    printf("请输入报数间隔:");
    scanf("%d",&M);
    printf("请输入获胜人数:");
    scanf("%d",&K);
    int isEliminated[N+1];
    int eliminateCount = 0;
    int currentPos = 0;
    int countNum = 0;
    for(int i=0;i<=N+1;i++)
        isEliminated[i] = 0;
       
    while (eliminateCount < N - K) {
        currentPos = (currentPos % N) + 1;
        if (!isEliminated[currentPos]) {
            countNum++;
            if(countNum % M == 0) {
                isEliminated[currentPos] = 1;
                eliminateCount++;
            }
        }
    }
    printf("最终剩余%d个获胜座位", K);
    for (int i = 1; i <= N; i++) {
        if (!isEliminated[i]) {
            printf("%d ", i);
        }
    }
    printf("\n");
    return 0;
}
```
![700](assets/1-29/file-20260129210143912.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB