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个函数的更多相关文章

  1. abs()函数的返回值问题

    转载原文地址:http://www.cnblogs.com/webary/p/4967868.html 在牛客网看到一道关于abs()函数返回值的题目,见下图,当时还没反应过来,第一反应是:自从我开始 ...

  2. Python 函数参数引用(传值/传址)/copy/deepcopy

    精简版: 传值:被调函数局部变量改变不会影响主调函数局部变量 传址:被调函数局部变量改变会影响主调函数局部变量 Python参数传递方式:传递对象引用(传值和传址的混合方式),如果是数字,字符串,元组 ...

  3. 那个你经常用的abs函数(取绝对值)真的总是返回非负数吗?

    前几天在牛客网看到一道关于abs()函数返回值的题目,见下图,当时还没反应过来,第一反应是:自从我开始学C语言,就知道它是用来求int数的绝对值的,返回值当然是0或者正数啊,一看答案就是A. 后来思来 ...

  4. Delphi 数学函数:常用的几个数学函数(Power、Abs、Int、Trunc、Round、Frac、sqr、sqrt)

    Delphi 常用的几个数学函数 1 Power函数,求次方 定义:function Power(X,Y): (Same type as parameter); 说明:X可以是整型,也可以是实型:返回 ...

  5. Python高手之路【三】python基础之函数

    基本数据类型补充: set 是一个无序且不重复的元素集合 class set(object): """ set() -> new empty set object ...

  6. Delphi 使用之函数

    函数由一句或多句代码组成,可以实现某个特定的功能.使用函数可以使代码更加易读.易懂,加快编程速度及减少重复代码.过程与函数类似,过程与函数最重要的区别在于,过程没有返回值,而函数能有返回值.     ...

  7. Excel函数进阶

    #笔记:为了方便自己以后查找,以便随时随地能查看.形成系统化学习! 查找引用函数 ------------------包含----------Vlookup函数(if数组).Hlookup函数.loo ...

  8. 人生苦短之我用Python篇(遍历、函数、类)

    #遍历 info = {'key1':'value1','key2':'value2','key3':'value3'} #方式一 for i in info: print(i,info[i]) #方 ...

  9. python学习道路(day4note)(函数,形参实参位置参数匿名参数,匿名函数,高阶函数,镶嵌函数)

    1.函数 2种编程方法 关键词面向对象:华山派 --->> 类----->class面向过程:少林派 -->> 过程--->def 函数式编程:逍遥派 --> ...

随机推荐

  1. 第三十六节,os系统级别操作模块

    在使用os模块时需要先 import os 引入模块 os.getcwd()模块函数 功能:获取当前工作目录,即当前python脚本工作的目录路径[无参] 使用方法:os.getcwd() 格式如:a ...

  2. nginx配置错误

    重启nginx:sudo /usr/local/nginx/sbin/nginx -s reload 出现错误提示:nginx: [emerg] unknown directive "if& ...

  3. IBM Mq Spring JMS 的xml配置

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  4. java web服务器tomcat介绍【转载】

    机器矩阵2016-08-10 22:14 java程序员亲切地称他为tom猫,看到这只猫可以说明1 服务器部署成功了 ,2 网络是联通的. 到底这只猫是什么来头呢? tomcat是Apache基金会下 ...

  5. Windows下搭建PHP开发环境【总结】

    一.准备工作-下载所需软件 Apache 进入apache服务器官网http://httpd.apache.org/ ,下面是下载的教程:http://jingyan.baidu.com/articl ...

  6. IIS express 7.5 设置默认文档

    在C:\Users\[电脑用户名]\Documents\IISExpress\config 下面有个applicationhost.config文件,打开文件找到<system.webServe ...

  7. iOS 判断数组不为空

    if (array != nil && ![array isKindOfClass:[NSNull class]] && array.count != 0)

  8. 怎样将MySQL数据库上传到服务器

    首先,需要将本地的数据库导出来,作为一个数据文件,以备稍后上传到服务器用,在本地登陆phpmyadmin控制面板: 登陆成功后,在左侧选择需要操作的数据库: 选择后,页面会自动刷新,然后再在右边点击[ ...

  9. oracle 锁表的处理。

    最近系统每天经常锁表,进程杀死后,很快再次锁住这个表. (一)先贴出现场处理死锁的步骤. 另外:有时候通过PL/SQL执行kill session可能仍然无法解锁,此时需要登陆到Oracle服务器将进 ...

  10. Java Interrupt Related

    In Java, the main process can have several threads at a time, but only a few of them can run concurr ...