当前位置: 首页> 文旅> 文化 > 无锡做网站公司哪家比较好_高德地图可以搜索国外吗_百度竞价排名事件_seo入门教程

无锡做网站公司哪家比较好_高德地图可以搜索国外吗_百度竞价排名事件_seo入门教程

时间:2025/7/9 22:05:22来源:https://blog.csdn.net/basketball616/article/details/146771599 浏览次数:0次
无锡做网站公司哪家比较好_高德地图可以搜索国外吗_百度竞价排名事件_seo入门教程

常用算术生成算法

学习目标:

  • 掌握常用的算术生成算法

注意:

  • 算术生成算法属于小型算法,使用时包含的头文件为 #include <numeric>

算法简介:

  • accumulate // 计算容器元素累计总和

  • fill // 向容器中添加元素

accumulate

功能描述:

  • 计算区间内容器元素累计总和

函数原型:

  • accumulate(iterator beg, iterator end, value);

    • beg:开始迭代器

    • end:结束迭代器

    • value:起始值

#include <iostream>
#include <vector>
#include <numeric>using namespace std;int main() {// 创建一个包含多个元素的 vectorvector<int> v = {1, 2, 3, 4, 5};// 输出容器的内容cout << "容器的内容: ";for (auto it = v.begin(); it != v.end(); it++) {cout << (*it) << " ";}cout << endl;// 计算容器元素的总和,起始值为 0int sum = accumulate(v.begin(), v.end(), 0);// 输出总和cout << "容器元素的总和: " << sum << endl;return 0;
}

fill

功能描述:

  • 向容器中填充指定的元素

函数原型:

  • fill(iterator beg, iterator end, value);

    • beg:开始迭代器

    • end:结束迭代器

    • value:填充的值

#include <iostream>
#include <vector>
#include <algorithm>using namespace std;int main() {// 创建一个空的 vector 容器vector<int> v = {1,2,3,4,5};// 输出填充前的容器内容cout << "填充前的容器内容: ";for (auto it = v.begin(); it != v.end(); it++) {cout << (*it) << " ";}cout << endl;// 使用 fill 函数将容器中的元素全部填充为 10fill(v.begin(), v.end(), 10);// 输出填充后的容器内容cout << "填充后的容器内容: ";for (auto it = v.begin(); it != v.end(); it++) {cout << (*it) << " ";}cout << endl;return 0;
}

关键字:无锡做网站公司哪家比较好_高德地图可以搜索国外吗_百度竞价排名事件_seo入门教程

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: