下面是另一个示例,使用is_permutation检查字符串是否为其它字符串的置换: #include<iostream>#include<algorithm>#include<string>intmain(){std::string str1="abc";std::string str2="bca";if(std::is_permutation(str1.begin(),str1.end(),str2.begin())){std::cout<<"str1 and str2 are permutati...
if(is_permutation(v1.begin(),v1.end(),v2.begin())) cout<<"Yes ,v1 and v2 is permutation!"<<endl; else cout<<"No ,v1 and v2 is not permutation!"<<endl; if(is_permutation(v1.begin(),v1.end(),v3.begin())) cout<<"Yes ,v1 and v3 is permutation!"<<endl; else cout<...
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator first2, BinaryPredicate pred); 参数first1:它是[first1,last1)第一个元素的输入迭代器。last1:它是[first1,last1)最后一个元素的输入迭代器。first2:它是[first2,last2)第一个元素的输入迭代器。
is_permutation(a.begin(), a.end(), // 效果与无谓词版相同 b.begin(), [](const int &i1, const int &i2){ return i1 == i2; }); if(ret == true){ std::cout << "a is b sub_permutation\n"; }else{ std::cout << "a not is b sub_permutation\n"; } } /* 结果: a...
bool is_permutation (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred); 功能: 判断区间[ first1 , last1 )是否是以first2为开始的区间的一个排列,如果是,返回真。 例子: // is_permutation example ...
is_partitioned is_permutation is_sorted is_sorted_until iter_swap lexicographical_compare lower_bound make_checked_array_iterator make_heap max max_element merge min min_element minmax_element minmax mismatch <alg> move move_backward next_permutation nth_element none_of partial_sort partial_sort_cop...
下面的例子展示了 std::algorithm::is_permutation() 函数的用法。 #include <iostream> #include <vector> #include <algorithm> using namespace std; bool ignore_case(char a, char b) { return (tolower(a) == tolower(b)); } int main(void) { vector<char> v1 = {'A', 'B', 'C', '...
constexpr bool is_permutation( ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, ForwardIt2 last2, BinaryPredicate p ); (C++20 起) 若存在范围 [first1, last1) 中元素的排列,使得该范围等于 [first2,last2) ,则返回 true ,若不给出,则其中 last2 代表first2 + (last1 - first1) ...
template<class ForwardIt1, class ForwardIt2> bool is_permutation(ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first) { // 跳过公共前缀 std::tie(first, d_first) = std::mismatch(first, last, d_first); // 在 rest 上迭代,计数 [d_first, d_last) 中出现多少次 // 每个来自 [...
{7,5,8,9}; ios::sync_with_stdio(0); do{ for(int i = 0; i<4; ++i) cout<<a[i]<<" "; cout<<endl; }while(next_permutation(a,a+4)); if(is_permutation(a,a+4,b)) //c++11之后有 cout<<"true"<<endl; else cout<<"false"<<endl; for(int i = 0; i<4; ++i) cout...