<分区>
我的作业遇到了一些麻烦。我有一个包含 30 个单词的字符串数组。我必须将其中三个词组合起来形成一个密码组合。 “airairair”或“allallall”等组合是可以接受的。我知道我应该有 27000 个组合(30 * 30 * 30),但到目前为止我只得到 900 个。有人可以帮我吗?我究竟做错了什么?代码如下:
#include<iostream>
#include<string>
#include<list>
#include<fstream>
using namespace std;
int main(int argc, char **argv[])
{
string passwords[] = { "air", "few", "all", "one", "cot", "jam", "sip", "gag", "arc", "egg",
"had", "hut", "tan", "paw", "pay", "got", "get", "pea", "rig", "cop",
"sat", "two", "who", "six", "sow", "dam", "tip", "lit", "awl", "dew" };
static int numWords = 0;
static int count = 0;
int arrLength = sizeof(passwords) / sizeof(passwords[0]);
ofstream f("passwords.dat"); //write passwords to file
int i, j, k;
for (i = 0; i < arrLength; i++)
{
for ( j = 0; i < arrLength; i++)
{
for ( k = 0 ; k < arrLength; k++)
{
cout << passwords[i] << passwords[j] << passwords[k];
f << passwords[i] << passwords[j] << passwords[k] << "\n";
}
}
}
f.close();
system("pause");
return 0;
}