用代码实现的,A与a表示父子,运行结果是240,求验证 #include <vector> #include <iostream> #include <string> #include <algorithm> using namespace std; int main(int argv, char** argc) { vector<char> member = { 'A', 'B', 'C', 'a', 'b', 'c' }; int b = 1; //ABCabc本身是满足要求的一个排列,所以计数从1开始 int flag = 0; while (next_permutation(member.begin(), member.end())) { for (auto i = member.begin(); i != --member.end(); ++i) { if (((*i) - *(i + 1)) == 32 || ((*i) - *(i + 1)) == -32) flag = 1; //父子站在了一起 } if (flag == 1) flag = 0; else ++b; //满足要求,计数加1 } cout << b << endl; }