copy ,abs,includes 3个函数
copy:
Copy函数原型:标头: <algorithm>
OutputIterator copy(
InputIterator begin,
InputIterator end,
outputIterator Result)
返回的结果为:OutputIterator容器的Result到Result+(end-begin)位置被InputIterator
容器begin到end位置的数据覆盖。[begin,end)
#include
<vector>
#include
<algorithm>
#include
<iostream>
using namespace std;
void main()
{
vector<int> vec1,vec2;
for(int i=0;i<=5;++i)
{
vec1.push_back(i*2);
}
for(int i=0;i<=10;++i)
{
vec2.push_back(i*3);
}
cout<<"vec1 数据项依次为:";
for(vector<int>::iterator iter=vec1.begin();iter!=vec1.end();iter++)
{
cout<<*iter<<" ";
}
cout<<endl<<"vec2的数据项依次为:";
for(vector<int>::iterator iter=vec2.begin();iter!=vec2.end();iter++)
{
cout<<*iter<<" ";
}
//copy,更新vec2的数据,
copy(vec1.begin(),vec1.end(),vec2.begin());
cout<<endl<<"更新后的vec2:";
for(vector<int>::iterator iter=vec2.begin();iter!=vec2.end();iter++)
{
cout<<*iter<<" ";
}
system("pause");
}
abs: 数据的绝对值
#include
<iostream>
#include
<valarray>
using namespace std;
const int nums=10;
void main()
{
//集合应用
valarray<int> val_old(nums);
for(int i=0;i<nums;++i)
{
val_old[i]=-i;
}
cout<<"the size of val_old
is :"<<val_old.size()<<endl;
cout<<"before abs list is: ";
for(int i=0;i<nums;++i)
{
cout<<val_old[i];
if(i<nums-1)
{
cout<<",";
}
}
valarray<int> val_new=abs(val_old);
//将整合集合对象传给方法,每个元素都变
cout<<endl<<"after abs:";
for(int i=0;i<nums;++i)
{
cout<<val_new[i];
if(i<nums-1)
{
cout<<",";
}
}
//单个对象。
double d=-9.909;
double abs_d=abs(d);
cout<<endl<<abs_d+d;
system("pause");
}
includes:标头: <algorithm>
函数原型:bool includes(
InputIterator1 First1,
InputIterator1 Last1,
InputIterator2 First2,
InputIterator2 Last2
)
集合序列与集合序列之间的包含与否!
#include
<iostream>
#include
<algorithm>
#include
<functional>
#include
<string>
#include
<deque>
using namespace std;
int main()
{
deque<string>::size_type nums=5;
deque<string> strs_big(nums);
deque<string> strs_small(3);
strs_big.push_back("one");
strs_big.push_back("two");
strs_big.push_back("three");
strs_big.push_back("four");
strs_big.push_back("");
strs_small.push_back("");
strs_small.push_back("two");
strs_small.push_back("four");
sort(strs_big.begin(),strs_big.end());
sort(strs_small.begin(),strs_small.end());
cout<<endl<<"较大串的数据元素有:";
for(deque<string>::iterator ite=strs_big.begin();ite!=strs_big.end();++ite)
{
cout<<*ite<<" ";
}
cout<<endl<<"较小串的数据元素有:";
for(deque<string>::iterator it=strs_small.begin();it!=strs_small.end();++it)
{
cout<<*it<<" ";
}
if(includes(strs_big.begin(),strs_big.end(),strs_small.begin(),strs_small.end()))
{
cout<<endl<<"大串包含小串!Y";
}
else
{
cout<<endl<<"大串不包含小串!N";
}
system("pause");
}
copy ,abs,includes 3个函数的更多相关文章
- abs()函数的返回值问题
转载原文地址:http://www.cnblogs.com/webary/p/4967868.html 在牛客网看到一道关于abs()函数返回值的题目,见下图,当时还没反应过来,第一反应是:自从我开始 ...
- Python 函数参数引用(传值/传址)/copy/deepcopy
精简版: 传值:被调函数局部变量改变不会影响主调函数局部变量 传址:被调函数局部变量改变会影响主调函数局部变量 Python参数传递方式:传递对象引用(传值和传址的混合方式),如果是数字,字符串,元组 ...
- 那个你经常用的abs函数(取绝对值)真的总是返回非负数吗?
前几天在牛客网看到一道关于abs()函数返回值的题目,见下图,当时还没反应过来,第一反应是:自从我开始学C语言,就知道它是用来求int数的绝对值的,返回值当然是0或者正数啊,一看答案就是A. 后来思来 ...
- Delphi 数学函数:常用的几个数学函数(Power、Abs、Int、Trunc、Round、Frac、sqr、sqrt)
Delphi 常用的几个数学函数 1 Power函数,求次方 定义:function Power(X,Y): (Same type as parameter); 说明:X可以是整型,也可以是实型:返回 ...
- Python高手之路【三】python基础之函数
基本数据类型补充: set 是一个无序且不重复的元素集合 class set(object): """ set() -> new empty set object ...
- Delphi 使用之函数
函数由一句或多句代码组成,可以实现某个特定的功能.使用函数可以使代码更加易读.易懂,加快编程速度及减少重复代码.过程与函数类似,过程与函数最重要的区别在于,过程没有返回值,而函数能有返回值. ...
- Excel函数进阶
#笔记:为了方便自己以后查找,以便随时随地能查看.形成系统化学习! 查找引用函数 ------------------包含----------Vlookup函数(if数组).Hlookup函数.loo ...
- 人生苦短之我用Python篇(遍历、函数、类)
#遍历 info = {'key1':'value1','key2':'value2','key3':'value3'} #方式一 for i in info: print(i,info[i]) #方 ...
- python学习道路(day4note)(函数,形参实参位置参数匿名参数,匿名函数,高阶函数,镶嵌函数)
1.函数 2种编程方法 关键词面向对象:华山派 --->> 类----->class面向过程:少林派 -->> 过程--->def 函数式编程:逍遥派 --> ...
随机推荐
- CDN技术详解及实现原理
CDN技术详解 一本好的入门书是带你进入陌生领域的明灯,<CDN技术详解>绝对是带你进入CDN行业的那盏最亮的明灯.因此,虽然只是纯粹的重点抄录,我也要把<CDN技术详解>的精 ...
- JavaScript高级程序设计:第十七章
错误处理与调试 一.错误处理 1.try-catch语句: ECMA-262第3版引入了try-catch语句,作为javascript中处理异常的一种标准方式.基本的语法如下: try { //可能 ...
- nfs服务器的建立
NFS服务器的配置 一.NFS服务器端的配置,即共享发布者 (一)需启动的服务和需安装的软件 1.NFS服务器必须启动两个daemons服务:rpc.nfsd和rpc.mountd rpc.nfs ...
- hdu_4547_CD操作(在线LCA)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4547 题意:中文,不解释 题解:很裸的LCA,注意父目录打开子目录一次就够了,这里我才用倍增在线LCA ...
- 错误: libstdc++.so.6: cannot open shared object file: No such file or directory
解压完别人提供的openwrt代码,编译时,出现如下错误: # configuration written to .config#mips-openwrt-linux-uclibc-gcc: erro ...
- 自动加载U盘
编辑/etc/fstab 比如想在开机的时候将/dev/sda1安装在/mnt 可以在/etc/fstab中加入一行 /dev/sda1 /mnt ext3 defaults 0 ...
- Nicholas C. Zakas谈怎样才能成为优秀的前端工程师
黄色阴影为业务,红色字体为哲学 昨天,我负责了Yahoo!公司组织的一次面试活动,感触颇深的是其中的应聘者提问环节.我得说自己对应聘者们提出的大多数问题都相当失望.我希望听到一些对在Yahoo!工作充 ...
- (转载)解析ISO8583报文实例
本篇文章参考了中国银联POS终端规范,所以如有不明白的可以去我的资源里面下载. 现在我们有ISO8583报文如下(十六进制表示法): 60 00 03 00 00(前五个字节为TPDU) 60 31 ...
- 12.04 ubuntu 更改IP
在一个局域网里面,如果是自动获取IP,就会导致IP冲突 进入要连接的热点进行设置 IPV4 Setting address netmask ...
- jquery给html元素添加内容
append() - 在被选元素的结尾插入内容 prepend() - 在被选元素的开头插入内容 after() - 在被选元素之后插入内容 before() - 在被选元素之前插入内容 实例 $(& ...