我到目前为止是这样的:
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
string genePool[16] = {"aa", "ab", "ac", "ad", "ba", "bb", "bc", "bd", "ca", "cb",
"cc", "cd", "da", "db", "dc", "dd"};
string coco, code, deco, dede;
int total = 0;
for (int i = 0; i < 16; i++){
coco = genePool[i];
for (int j = 0; j < 15; j++){
code = genePool[j];
for (int k = 0; k < 14; k++){
code = genePool[k];
for (int l = 0; l < 13; l++){
code = genePool[l];
size_t a = count(coco.begin(), coco.end(), 'a') +
count(code.begin(), code.end(), 'a') +
count(deco.begin(), deco.end(), 'a') +
count(dede.begin(), dede.end(), 'a');
size_t b = count(coco.begin(), coco.end(), 'b') +
count(code.begin(), code.end(), 'b') +
count(deco.begin(), deco.end(), 'b') +
count(dede.begin(), dede.end(), 'b');
size_t c = count(coco.begin(), coco.end(), 'c') +
count(code.begin(), code.end(), 'c') +
count(deco.begin(), deco.end(), 'c') +
count(dede.begin(), dede.end(), 'c');
size_t d = count(coco.begin(), coco.end(), 'd') +
count(code.begin(), code.end(), 'd') +
count(deco.begin(), deco.end(), 'd') +
count(dede.begin(), dede.end(), 'd');
if (a = 2 || b = 2 || and c = 2 || d = 2){
total++;
cout << total << ") "coco << "," << code << "," << deco
<< "," << dede << endl;
}
}
}
}
}
return 0;
}
自从我用 C++ 做任何事情以来已经有一段时间了,即使那时我也没有走得太远,所以请原谅任何令人反感的明显错误。每当有人指出更好时,我都会尽心尽责地做得更好:)