2024团体程序设计天梯赛L1-102 兰州牛肉面

这篇文章详细描述了一个C++程序,用户输入一系列数字,程序动态存储并累加这些数字,最后计算总和并输出,保留两位小数精度。

#include<iostream>
#include<stdio.h>
#include<iomanip>
using namespace std;
int n, a[105], c, d;
double p[105], ans;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> p[i];
    while(1) {
        cin >> c >> d;
        if (!c) break;
        a[c]+=d;
    }
    for (int i = 1; i <= n; i++) {
        cout << a[i] << endl;
        ans += a[i] * p[i];
    }
    cout << fixed << setprecision(2) << ans <<endl;
}

### 解析 L1-071 题目 #### 题目背景描述 静静姐正在处理一份来自某企业人力资源部门的要求,该企业希望获得一批通过特定筛选条件的学生名单。这些学生参加了2022年的团体程序设计天梯赛,并且满足一定的分数门槛和其他附加条件[^2]。 #### 问题核心需求 为了响应这一请求,需要编写一段程序来处理参赛者的成绩列表,从中挑选出符合条件的候选人并按照批次输出推荐名单。具体来说: - 推荐对象仅限于那些得分达到或超过175分的选手; - 同一推荐批次内的学生成绩需保持严格递增趋势; - 对于成绩相等情况下的特殊考量:如果一名学生的竞赛成绩与前一位相同,但是此人在PAT考试中有合格表现,则允许例外加入同一组别。 #### 数据输入说明 给定一组整数表示各参赛者在比赛中的最终得分以及他们是否具备额外资格(即是否有有效的PAT成绩)。此外还需指定K值代表总共要产生的独立推荐批次数量。 #### 输出预期结果 对于每一个k (1 ≤ k ≤ K),依次打印出第k批被选中成员的成绩序列,每行一个数值直到结束当前轮次的选择过程为止。 --- ```cpp #include <iostream> #include <vector> #include <algorithm> using namespace std; struct Student { int score; bool hasPat; // 是否有PAT成绩 bool operator<(const Student& other) const { return score < other.score || (score == other.score && !hasPat); } }; int main() { vector<Student> students; int n, m, patLine, lgeScore; cin >> n >> m >> patLine; for(int i=0;i<n;++i){ cin>>lgeScore; if(lgeScore>=175){ students.push_back({lgeScore,false}); }else{ continue; } char c; cin>>c; if(c=='Y'){ students.back().hasPat=true; } } sort(students.begin(),students.end()); int batchCount = 0; while (!students.empty()) { ++batchCount; cout << "Batch #" << batchCount << ":" << endl; auto it = unique_if_not_pat(students.begin(), students.end(), [](Student a, Student b){return a.score==b.score&&!a.hasPat&&b.hasPat;}); for(auto iter = students.begin();iter!=it;++iter){ cout<<(*iter).score<<"\n"; } students.erase(it, students.end()); if(batchCount >= m){ break; } } } ``` 上述代码实现了基本逻辑框架,但`unique_if_not_pat`函数并未定义,在实际应用时应当替换为标准库提供的合适算法或者自定义实现以完成去重操作,确保当存在重复分数而后者拥有PAT证书的情况下能够保留后者进入下一轮比较。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值