topic:
next_permutation () function describes: next_permutation (a, a + n) is a function of the array a full array, there is a requirement prior to use next_permutation () function, is to achieve an array of a line up in ascending order of Therefore next_permutation () function and the general sort () function used in combination.
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
string str = "AA223344";
int main()
{
sort(str.begin(),str.end()); //在使用next_permutation()函数之前先要使 数组中的元素按照字典序从小到大排序
do
{
int fA = str.find('A',0);
int sA = str.find('A',fA+1);
int f2 = str.find('2',0);
int s2 = str.find('2',f2+1);
int f3 = str.find('3',0);
int s3 = str.find('3',f3+1);
int f4 = str.find('4',0);
int s4 = str.find('4',f4+1);
if((sA-fA==2)&&(s2-f2==3)&&(s3-f3==4)&&(s4-f4==5))
{
cout << str << endl;
return 0;
}
}while(next_permutation(str.begin(),str.end()));
return 0;
}