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 函数式编程:逍遥派 --> ...
随机推荐
- 第二十六节,Python内置函数
Python3.0内置函数 abs() 取数字的绝对值,也就是无论是正数还是负数取它的绝对值格式:abs(目标变量)返回:数字类型 #!/usr/bin/env python # -*- coding ...
- java中的静态代码块等执行顺序
http://www.cnblogs.com/naruto469/p/3608459.html public class Print { 2 3 public Print(String s){ 4 S ...
- 【Machine Learning in Action --2】K-近邻算法构造手写识别系统
为了简单起见,这里构造的系统只能识别数字0到9,需要识别的数字已经使用图形处理软件,处理成具有相同的色彩和大小:宽高是32像素的黑白图像.尽管采用文本格式存储图像不能有效地利用内存空间,但是为了方便理 ...
- angular中的ng-bind-html指令和$sce服务
angular js的强大之处之一就是他的数据双向绑定这一牛B功能,我们会常常用到的两个东西就是ng-bind和针对form的ng-model.但在我们的项目当中会遇到这样的情况,后台返回的数据中带有 ...
- 用ios做的一个简单的记事本
#import "ViewController.h" @interface ViewController ()@property (weak, nonatomic) IBOutle ...
- iOS中date和string的相互转换
必须知道的内容 G: 公元时代,例如AD公元 yy: 年的后2位 yyyy: 完整年 MM: 月,显示为1-12 MMM: 月,显示为英文月份简写,如 Jan ...
- Linux raid信息 查看
Linux下查看软.硬raid信息的方法. 软件raid:只能通过Linux系统本身来查看 cat /proc/mdstat 可以看到raid级别,状态等信息. 硬件raid: 最佳的办法是通过已安装 ...
- asp之Eval()函数
运行字符串: a=Eval("1+1") 结果为:a=2 运行函数: function aa(a) aa=a+1 end function b=Eval("aa(2)&q ...
- asp:Property解释与例子
=======================================================================Property Get 语句在 Class 块中,声明构 ...
- Windsock套接字I/O模型学习 --- 第二章
1. select模型 select模型主要借助于apiselect来实现,所以先介绍一下select函数 int select( int nfds, // 忽略,仅是为了与 Berkeley 套接字 ...