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 ...
随机推荐
- 用绿色版TOMCAT和绿色版JDK安装一个WEB服务器
(1) 使用绿色版本JDK,解压到一个目录上D:\jdk1.6. (2) 使用绿色版本Tomcat,解压到另一个目录上D:\jdk1.6\tomcat5.5 只要在bat文件D:\tomcat5. ...
- 提升Essay写作质量,可从这三个层次入手
“有针对性”读书对写Essay的产生的帮助是非常大的.由浅显的直接成效,到深度的铺垫积累,阅读一共可分为三个层次: 1读Essay: 2读与写作题材相关的材料: 3多样化阅读. 第一层次:读Essay ...
- 51nod 1163:最高的奖励 优先队列
1163 最高的奖励 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励.在结束时间之前完成该 ...
- windows系统下使用mycat实现mysql数据库的主从复制,从而实现负载均衡
在之前有记录过在一台系统中安装多台数据库,同时实现主从复制,但是那个主从复制只是一个基于dosc命令的,再实际的开发中我们不会去直接连接数据库,一般情况下我们也是通过间接的采用一些中间件去连接,本来是 ...
- openCV 3.4 windows下的配置说明
链接: https://pan.baidu.com/s/1dkS_G8ZSBD8EnhYeEFZxhQ 密码: xu99 (从官网下的, 但360会提示有毒, 哈哈哈) 运行exe, 解压openCV ...
- Day6 - B - 采花 HYSBZ - 2743
萧芸斓是Z国的公主,平时的一大爱好是采花.今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花 .花园足够大,容纳了n朵花,花有c种颜色(用整数1-c表示),且花是排成一排的,以便于公主采花.公 ...
- Redis详解(六)——哨兵机制
Redis详解(六)--哨兵机制 一.概述 Redis Sentinel是一个分布式系统,为Redis提供高可用性解决方案.可以在一个架构中运行多个 Sentinel 进程(progress), 这些 ...
- java关键字“static”
Java中static使用方法 1.static静态变量 静态变量:每个类只有一个,所有实例共享: 实例变量:每个实例只有一个: package test2; import java.lang.Str ...
- [PHP] php作为websocket的客户端实时读取推送日志文件
首先要使用composer来下载一个第三方扩展就可以实现php的websocket客户端,直接在当前目录生成下composer.json文件就可以了composer require textalk/w ...
- 使用delphi TThread类创建线程备忘录
备忘,不常用经常忘了细节 TMyThread = class(TThread) private { Private declarations } protected procedure Execute ...