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;
}
05-18 00:56