c++ STD Gems07
reverse、rotate、permutation
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <random>
template<class Container>
void write_to_cout(Container& container, const char* delimiter = " ")
{
std::copy(container.begin(), container.end(),
std::ostream_iterator<typename Container::value_type>(std::cout, delimiter) );
}
void test0()
{
std::vector<std::string> a = {"zero", "one", "two", "three", "four", "five", "six"};
std::vector<std::string> b = {"0", "1", "2", "3", "4", "5", "6"};
write_to_cout(a);
std::cout << std::endl;
//test
std::rotate(a.begin(), a.begin() + 3, a.end());
write_to_cout(a);
std::cout << std::endl << std::endl;
}
void test1()
{
std::vector<std::string> b = {"0", "1", "2", "3", "4", "5", "6"};
write_to_cout(b);
std::cout << std::endl;
// test
std::reverse(b.begin(), b.end());
write_to_cout(b);
std::cout << std::endl << std::endl;
}
void test2()
{
std::vector<std::string> a = {"zero", "one", "two", "three", "four", "five", "six"};
write_to_cout(a);
std::cout << std::endl;
//test algorithm
std::mt19937 rng( std::random_device{}() );
std::shuffle(a.begin(), a.end(), rng);
write_to_cout(a);
std::cout << std::endl << std::endl;
}
void test3()
{
std::string s = "abc";
std::string s1 = "adc";
std::string s2 = "acb";
//test 全排列
while( std::next_permutation(s.begin(), s.end() ) )
{
std::cout << s << "\n";
}
std::cout << std::endl;
std::cout << std::is_permutation(s.begin(), s.end(), s1.begin() ) << std:: endl;
std::cout << std::is_permutation(s.begin(), s.end(), s2.begin() ) << std:: endl;
}
int main()
{
test0();
test1();
test2();
test3();
return 0;
}
c++ STD Gems07的更多相关文章
- 【NX二次开发】NX内部函数,libuifw.dll文件中的内部函数
本文分为两部分:"带参数的函数"和 "带修饰的函数". 浏览这篇博客前请先阅读: [NX二次开发]NX内部函数,查找内部函数的方法 带参数的函数: void U ...
- C++ std::set
std::set template < class T, // set::key_type/value_type class Compare = less<T>, // set::k ...
- C++ std::priority_queue
std::priority_queue template <class T, class Container = vector<T>, class Compare = less< ...
- C++ std::queue
std::queue template <class T, class Container = deque<T> > class queue; FIFO queue queue ...
- C++ std::multimap
std::multimap template < class Key, // multimap::key_type class T, // multimap::mapped_type class ...
- C++ std::map
std::map template < class Key, // map::key_type class T, // map::mapped_type class Compare = less ...
- C++ std::list
std::list template < class T, class Alloc = allocator > class list; List Lists are sequence co ...
- C++ std::forward_list
std::forward_list template < class T, class Alloc = allocator > class forward_list; Forward li ...
- C++ std::deque
std::deque template < class T, class Alloc = allocator > class deque; Double ended queue deque ...
随机推荐
- 「Luogu2264」情书
传送门 Luogu 解题思路 字符串模拟SB题,STL随便搞. 详情见代码. 细节注意事项 STL总得会吧. 参考代码 #include <algorithm> #include < ...
- C++ Primer Plus 6 笔记(3)
第5章 1.cout在显示bool值之前将它们转换为int,但cout.setf(ios:: boolalpha)函数调用设置了一个标记,该标记命令cout显示true和false,而不是1和0 2. ...
- 获取JSHANDLE句柄
A string can also be passed in instead of a function: const aHandle = await page.evaluateHandle('doc ...
- 织梦 dede runphp=yes SQL语句操作
个人实例dede:channelartlist 下循环出 channel 栏目 中的 文章 {dede:sql sql='select * from dede_arctype where reid = ...
- POJ 3436:ACM Computer Factory 网络流
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6247 Accepted: 2 ...
- MapReduce会自动忽略文件夹下的.开头的文件
MapReduce会自动忽略文件夹下的.开头的文件,跳过这些文件的处理.
- springboot整合logback集成elk实现日志的汇总、分析、统计和检索功能
在Spring Boot当中,默认使用logback进行log操作.logback支持将日志数据通过提供IP地址.端口号,以Socket的方式远程发送.在Spring Boot中,通常使用logbac ...
- 我的第一个爬虫【python selenium】
去年写的一个小功能,一年过得好快,好快! 目的:爬取京东商品详情页面的内容(商品名称.价格.评价数量)后存储到xls文档中,方便商家分析自己商品的动态. 软件:chrome(windows).chro ...
- 从三星官方uboot开始移植
移植前的准备 下载 android_uboot_smdkv210.tar.bz2 这个文件 开始移植 本人使用的开发板是九鼎的 x210,在三星 uboot 的主 Makefile 中找到了类似的 s ...
- svn全局设置过滤文件没有作用的解决办法
svn全局设置过滤文件,网上教程文章很多, 都说了怎么配置,没有强调配置内容的格式 导致用惯了git的人,上手配置后,不起作用. 下面是我的配置内容: .classpath .project .set ...