TB椰程 TypeBuddy 打字搭子

2025-09 · 3级 · 数组清零

GESP 标程 · 考级真题 · 代码 · cpp · 难度 4/5 · 共 777 字

CCF 原卷官方标程 · 数组与向量 · 本地编译通过

  • 2025-09
  • 数组与向量

正文

// GESP 2025-09 C++ 3级 编程题 1 · 数组清零
// 原题:https://oj.yecheng.tv/p/gs2509l3p1
// 官方原卷:https://gesp.ccf.org.cn/101/attach/1703975921385504.pdf
// 题意:小 A 有一个由个非负整数构成的数组 。
// 知识点:数组与向量
// 参考程序:CCF 原卷官方标程,PDF 抽取后已去行号;本地编译核验通过,供打字练习
// 原卷样例验证:样例验证 2/2 通过
//
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 105;
int n;
int a[N];
int cnt;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    while (1) {
        int mx = n;
        for (int i = 1; i <= n; i++)
            if (a[i] >= a[mx]) mx = i;
        if (a[mx] == 0) break;
        int mn = a[mx];
        for (int i = 1; i <= n; i++)
            if (a[i] > 0) mn = min(mn, a[i]);
        a[mx] -= mn;
        cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}

GESP 标程 · 考级真题的其它内容

打字首页 · 英语学习中心 · 词库画廊 · 编程打字 · 指法入门 · 天梯榜 · 数据分析 · 班级课堂 · 关于我们
椰程 TypeBuddy 打字搭子 —— 键盘指法练习 · 单词记忆 · 班级课堂 · 在线 PK