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 ...
随机推荐
- DeprecationWarning:'open()' is deprecated in mongoose>=4.11.0,use 'openUri()' instead or set the 'useMongoClient' option if using 'connect()' or 'createConnection'
mongoose.connect('mongodb://localhost/test');报错:(node:2752) DeprecationWarning: `open()` is deprecat ...
- 使用elk+redis搭建nginx日志分析平台(引)
http://www.cnblogs.com/yjf512/p/4199105.html elk+redis 搭建nginx日志分析平台 logstash,elasticsearch,kibana 怎 ...
- MySQL 通过SQL语句导出表为文件
SELECT * //你要导出的字段 FROM `tabel` //表名 INTO OUTFILE "D:\\file.txt" //导出的文件路径和文件名 LINES TERMI ...
- Phoenix与HBase集成进行数据分析
安装好Phoenix后配置环境变量 export PHOENIX_PATH=/opt/cloudera/parcels/APACHE_PHOENIX-4.14.0-cdh5.14.2.p0.3expo ...
- Mongoose多表查询
文章来自 两个表关联查询aggregate 多个表关联查询aggregate populate多表关联查询 多表查询的两个方式 一个是aggregate聚合 一个是populate Schema的外表 ...
- kali下的截图工具scrot、flameshot和deepin-scrot
对于这几个截图工具,精简好用的应该是deepin-scrot了,这是个和QQ截图有类似功能的Linux截图工具.flameshot的功能是最多的,也很好用,虽然有的功能用不上. 1.scrot安装和使 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-pencil
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- P1046 划拳
P1046 划拳 转跳点:
- 2.11 学习总结 之 ajax
一.说在前面 昨天 学习了 json 数据结构 今天 学习ajax 并使用 json 二.jquery的ajax操作 1.查询jquery的官方文档发现与ajax相关的jquey方法如下: 1)$. ...
- linux下anaconda的安装和使用
1.将python3设置为默认 直接执行这两个命令即可: sudo update-alternatives --install /usr/bin/python python /usr/bin/pyth ...