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

  1. 【NX二次开发】NX内部函数,libuifw.dll文件中的内部函数

    本文分为两部分:"带参数的函数"和 "带修饰的函数". 浏览这篇博客前请先阅读: [NX二次开发]NX内部函数,查找内部函数的方法 带参数的函数: void U ...

  2. C++ std::set

    std::set template < class T, // set::key_type/value_type class Compare = less<T>, // set::k ...

  3. C++ std::priority_queue

    std::priority_queue template <class T, class Container = vector<T>, class Compare = less< ...

  4. C++ std::queue

    std::queue template <class T, class Container = deque<T> > class queue; FIFO queue queue ...

  5. C++ std::multimap

    std::multimap template < class Key, // multimap::key_type class T, // multimap::mapped_type class ...

  6. C++ std::map

    std::map template < class Key, // map::key_type class T, // map::mapped_type class Compare = less ...

  7. C++ std::list

    std::list template < class T, class Alloc = allocator > class list; List Lists are sequence co ...

  8. C++ std::forward_list

    std::forward_list template < class T, class Alloc = allocator > class forward_list; Forward li ...

  9. C++ std::deque

    std::deque template < class T, class Alloc = allocator > class deque; Double ended queue deque ...

随机推荐

  1. RCast 66: 射影几何与Rho演算

    Greg Meredith与Isaac DeFrain和Christian Williams一起讨论了射影几何及其在Rho演算中的作用. 原文链接及音频 https://blog.rchain.coo ...

  2. Hessian Token权限认证

    博客分类: Hessian   添加Token验证,如何生成Token,计算方式如下,采用不可逆转的方式生成[MD5加密]: 服务器端存储Token,采用线程安全的Map 客户端在发送业务请求前,先去 ...

  3. struts2令牌(token)内部原理

      小菜最近接触了struts2中的令牌知识,由于该知识点比较重要,因此想弄明白些,于是满怀信心的上网查阅资料,结果让小菜很无奈,网上的资料千篇一律,总结出来就一句话:“访问页面时,在页面产生一个to ...

  4. UITree_study

    1.Create canvas 2.Add TreeView 3.Subscribe and unsubscribe events(订阅和取消订阅事件) 4.Data bind items it's ...

  5. Codeforces 546 E:士兵的旅行 最大网络流

    E. Soldier and Traveling time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. 解决使用还原卡的PC在2个月后要重新加入域的问题

    客户端正确操作: 1. 启动注册表编辑器. 要这样做, 请依次单击 开始 . 运行 , 类型 regedit 在 打开, 框, 然后单击 确定 . 2. 找到并单击以下注册表子项: HKEY_LOCA ...

  7. 编程题目:输入一个链表,输出该链表中倒数第k个节点

    两种方法 1.在链表的初始化数据中加入 num 数据, 每添加一个节点,num加1,每删除一个节点,num减1 查找倒数第k个元素,即 指向第一个节点的指针向后移动 num - k 步. 2.使用两个 ...

  8. ROS学习笔记3-基础课程之文件系统向导

    准备工作需要使用如下命令安装ros的教程: $ sudo apt-get install ros-<distro>-ros-tutorials 其中,distro为所用ros的发行版本,该 ...

  9. Day7 - F - C Looooops POJ - 2115

    A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != ...

  10. Excel中神奇的vlookup函数之基础应用

      1.问题:   如下示例,需要将右边的表格匹配上对应工号的销售额. 这属于vlookup函数最基础的单条件匹配应用,左边表称为A表.右边表称为B表. 2.vlookup函数套路介绍 vlookup ...