轻松的编程学习
首页
题库
学习路径
在线商城
能力地图
下载应用
登录 / 注册
菜单
第三步:数出超过门槛的有几种
👁️ 1 人浏览
💬 0 人评论
❤️ 添加收藏
(本条路线统一用
g++ -std=c++17 -O0 -Wall
编译)
提交你的答案
请登录后提交答案。
去登录
← ⚠️ 第二步:用算法把总数加出来
⚠️ 第四步:不合格的挡在门口 →
更多题目
改成"你好,有词"
输出"100 分"
把年龄改成 20
输出学习天数 30
修复:给文字加引号
修复:补上右括号
代码编辑器
语言:
python3
c11
cpp17
Ctrl
+
Enter
运行
👩🏫 AI
▶ 运行代码
重置代码
打印代码
#include <iostream> #include <memory> #include <vector> #include <string> #include <numeric> #include <algorithm> struct Item { static int made, gone; std::string name; int qty; Item(std::string n, int q) : name(std::move(n)), qty(q) { made++; } ~Item() { gone++; } }; int Item::made = 0; int Item::gone = 0; class Basket { public: void add(std::string name, int qty) { items_.push_back(std::make_unique<Item>(std::move(name), qty)); } int kinds() const { return static_cast<int>(items_.size()); } int total() const { return std::accumulate(items_.begin(), items_.end(), 0, [](int s, const std::unique_ptr<Item> &p) { return s + p->qty; }); } /* TODO: 用 STL 算法数出 qty 大于 line 的有几种(line 要抄进 lambda)*/ int many(int line) const { (void)line; return 0; } private: std::vector<std::unique_ptr<Item>> items_; }; int main() { Basket b; b.add("apple", 3); b.add("pear", 5); b.add("fig", 2); std::cout << b.total() << "/" << b.many(2) << "/" << b.many(9) << "\n"; return 0; }
本次输入:
输出:
👩🏫
AI
请登录后使用 AI 老师
×
登录后可获得解题思路、提示与错误分析。
去登录
关闭
🎉
恭喜你,回答正确!
系统判定:正确
我知道了
💬 题目评论
提交
全部评论
全部评论