STL神秘技巧

STL神秘技巧

技巧一:copy,reverse_copy

作用:复制一段区间内的数,给另一段区间
使用方法:

n=5;srand(time(0));
for(Yc i=1;i<=n;i++)
	a[i]=rand();
copy(a+1,a+n+1,b+1);
reverse_copy(b+1,b+n+1,c+1);pr("a:");
for(Yc i=1;i<=n;i++)
	write(a[i]),pc(' ');ps("");pr("b:");
for(Yc i=1;i<=n;i++)
	write(b[i]),pc(' ');ps("");pr("c:");
for(Yc i=1;i<=n;i++)	
	write(c[i]),pc(' ');ps("");
return 0;

运行结果:

a:11015 15016 13145 24246 14271
b:11015 15016 13145 24246 14271
c:14271 24246 13145 15016 11015

技巧二:next_permutation,pre_permutation

作用:生成全排列
使用方法:

n=3;
for(Yc i=1;i<=n;i++)
	a[i]=i;
do{
	for(Yc i=1;i<=n;i++)
		write(a[i]),pc(' ');ps("");
}while(next_permutation(a+1,a+n+1));

运行结果:

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

技巧三:max_element,min_element

作用:求得区间最值
使用方法:

n=5;srand(time(0));
for(Yc i=1;i<=n;i++)
	a[i]=rand();pr("a:");
for(Yc i=1;i<=n;i++)
	write(a[i]),pc(' ');ps("");
pr("max:");write(*max_element(a+1,a+n+1));ps("");
pr("min:");write(*min_element(a+1,a+n+1));ps(""); 

运行结果:

a:13301 2261 689 25814 25513
max:25814
min:689

技巧四:is_permutation

作用:判断一段区间是否为另一段区间的排列
使用方法:

posted @   yxans  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
点击右上角即可分享
微信分享提示