vault backup: 2026-01-29 21:02:30
This commit is contained in:
@@ -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[])
|
||||
```
|
||||

|
||||
**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;
|
||||
}
|
||||
```
|
||||

|
||||
BIN
YueQian/Homework/assets/1-29/file-20260129210143912.png
Normal file
BIN
YueQian/Homework/assets/1-29/file-20260129210143912.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
Reference in New Issue
Block a user